Initial commit
This commit is contained in:
commit
f2788efb82
9 changed files with 954 additions and 0 deletions
26
context.go
Normal file
26
context.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package csrf
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type contextKey int8
|
||||
|
||||
const (
|
||||
tokenContextKey contextKey = 1
|
||||
)
|
||||
|
||||
func setCSRFToken(ctx context.Context, token string) context.Context {
|
||||
newCtx := context.WithValue(ctx, tokenContextKey, token)
|
||||
return newCtx
|
||||
}
|
||||
|
||||
func GetCSRFToken(ctx context.Context) string {
|
||||
value := ctx.Value(tokenContextKey)
|
||||
strValue, ok := value.(string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strValue
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue