Files
ucan/toolkit/server/exectx/ctxvalue.go
2025-08-05 16:57:19 +02:00

17 lines
429 B
Go

package exectx
import "context"
type ctxKey struct{}
// AddUcanCtxToContext insert a UcanCtx into a go context.
func AddUcanCtxToContext(ctx context.Context, ucanCtx *UcanCtx) context.Context {
return context.WithValue(ctx, ctxKey{}, ucanCtx)
}
// FromContext retrieve a UcanCtx from a go context.
func FromContext(ctx context.Context) (*UcanCtx, bool) {
ucanCtx, ok := ctx.Value(ctxKey{}).(*UcanCtx)
return ucanCtx, ok
}