csrf/context.go

27 lines
411 B
Go
Raw Permalink Normal View History

2025-06-11 00:24:24 +05:00
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
}