Initial commit

This commit is contained in:
Ivan 2025-06-11 00:24:24 +05:00
commit f2788efb82
Signed by: landlord
GPG key ID: 416A03BC4ADA4CD7
9 changed files with 954 additions and 0 deletions

26
context.go Normal file
View 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
}