feat(06-01): grow router verbs, factories, and guard registry
- Add Post/Put/Patch/Delete on pact.Router and surf Router/Group - Resolve name:param middleware via RegisterMiddlewareFactory - Add bouncer.Registry with Guard, CredentialGuard, UnauthorizedWriter - Re-express jwt as NewJWTGuard without changing Middleware bodies
This commit is contained in:
@@ -26,3 +26,25 @@ func User(ctx context.Context) (*Principal, bool) {
|
||||
u, ok := ctx.Value(userKey{}).(*Principal)
|
||||
return u, ok && u != nil
|
||||
}
|
||||
|
||||
type credentialKey struct{}
|
||||
|
||||
// WithCredential stores the resolved credential (e.g. *ApiToken) on ctx.
|
||||
func WithCredential(ctx context.Context, cred any) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, credentialKey{}, cred)
|
||||
}
|
||||
|
||||
// Credential returns the resolved credential from ctx.
|
||||
func Credential(ctx context.Context) (any, bool) {
|
||||
if ctx == nil {
|
||||
return nil, false
|
||||
}
|
||||
c := ctx.Value(credentialKey{})
|
||||
if c == nil {
|
||||
return nil, false
|
||||
}
|
||||
return c, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user