24 lines
435 B
Go
24 lines
435 B
Go
|
package csrf
|
||
|
|
||
|
import "net/http"
|
||
|
|
||
|
type CSRF struct {
|
||
|
CSRFKey string
|
||
|
DeniedFn DenyFN
|
||
|
}
|
||
|
type DenyFN func(w http.ResponseWriter, r *http.Request)
|
||
|
|
||
|
// NewCSRFRand makes a new CSRF with a random key.
|
||
|
func NewRand(deniedfn DenyFN) CSRF {
|
||
|
k := SessionRandB64(16)
|
||
|
return New(k, deniedfn)
|
||
|
}
|
||
|
|
||
|
// NewCSRF creates a CSRF with a defined key
|
||
|
func New(key string, deniedfn DenyFN) CSRF {
|
||
|
return CSRF{
|
||
|
CSRFKey: key,
|
||
|
DeniedFn: deniedfn,
|
||
|
}
|
||
|
}
|