csrf/init.go

24 lines
435 B
Go
Raw Permalink Normal View History

2025-01-12 11:40:15 +00:00
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,
}
}