29 lines
595 B
Go
29 lines
595 B
Go
package membership
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"proxui/backend/internal/rbac"
|
|
)
|
|
|
|
type Membership struct {
|
|
TenantID string `json:"tenant_id"`
|
|
Role rbac.Role `json:"role"`
|
|
}
|
|
|
|
type contextKey struct{}
|
|
|
|
func ContextWithMembership(ctx context.Context, membership Membership) context.Context {
|
|
return context.WithValue(ctx, contextKey{}, membership)
|
|
}
|
|
|
|
func FromContext(ctx context.Context) (Membership, bool) {
|
|
membership, ok := ctx.Value(contextKey{}).(Membership)
|
|
return membership, ok
|
|
}
|
|
|
|
func FromRequest(r *http.Request) (Membership, bool) {
|
|
return FromContext(r.Context())
|
|
}
|