gate

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 3 Imported by: 12

Documentation

Index

Constants

View Source
const (
	FeatureUsersSignup        = "users.signup"
	FeatureUsersPasswordReset = "users.password_reset"
	// FeatureUsersPasswordResetFinalize duplicates the go-auth string (go-auth owns the literal).
	FeatureUsersPasswordResetFinalize = "users.password_reset.finalize"
)

Variables

This section is empty.

Functions

func AliasesFor

func AliasesFor(key string) []string

AliasesFor returns the legacy alias keys for the provided key, if any.

func IsAlias

func IsAlias(key string) bool

IsAlias reports whether the key is a known alias.

func NormalizeKey

func NormalizeKey(key string) string

NormalizeKey trims whitespace and resolves any known aliases (if configured).

func ResolveAlias

func ResolveAlias(key string) (string, bool)

ResolveAlias returns the normalized key and whether an alias was applied.

Types

type ActorClaims added in v0.5.0

type ActorClaims struct {
	SubjectID string
	TenantID  string
	OrgID     string
	Roles     []string
	Perms     []string
}

ActorClaims are the minimal inputs required to build a chain.

type ActorRef

type ActorRef struct {
	ID   string
	Type string
	Name string
}

ActorRef identifies the actor making a change to runtime overrides.

type ClaimsProvider added in v0.5.0

type ClaimsProvider interface {
	ClaimsFromContext(ctx context.Context) (ActorClaims, error)
}

ClaimsProvider derives claims from context.

type DefaultTrace

type DefaultTrace struct {
	Set   bool
	Value bool
	Error error
}

DefaultTrace captures config default resolution details.

type FeatureGate

type FeatureGate interface {
	Enabled(ctx context.Context, key string, opts ...ResolveOption) (bool, error)
}

FeatureGate resolves feature enablement for the current scope.

type MutableFeatureGate

type MutableFeatureGate interface {
	FeatureGate
	Set(ctx context.Context, key string, scope ScopeRef, enabled bool, actor ActorRef) error
	Unset(ctx context.Context, key string, scope ScopeRef, actor ActorRef) error
}

MutableFeatureGate supports runtime overrides for feature values.

type OverrideMatchTrace added in v0.5.0

type OverrideMatchTrace struct {
	Scope ScopeRef
	State OverrideState
	Value *bool
}

OverrideMatchTrace captures a single matched override for trace output.

type OverrideState

type OverrideState string

OverrideState captures the tri-state override status.

const (
	OverrideStateMissing  OverrideState = "missing"
	OverrideStateEnabled  OverrideState = "enabled"
	OverrideStateDisabled OverrideState = "disabled"
	OverrideStateUnset    OverrideState = "unset"
)

type OverrideTrace

type OverrideTrace struct {
	State   OverrideState
	Value   *bool
	Error   error
	Match   ScopeRef
	Matches []OverrideMatchTrace
}

OverrideTrace captures override resolution details.

type PermissionProvider added in v0.5.0

type PermissionProvider interface {
	Permissions(ctx context.Context, claims ActorClaims) ([]string, error)
}

PermissionProvider derives permissions from claims/roles.

type ResolveEvent

type ResolveEvent struct {
	Key           string
	NormalizedKey string
	Chain         ScopeChain
	Value         bool
	Source        ResolveSource
	Error         error
	Trace         ResolveTrace
}

ResolveEvent is emitted after resolution for hooks.

type ResolveHook

type ResolveHook interface {
	OnResolve(ctx context.Context, event ResolveEvent)
}

ResolveHook receives resolution events.

type ResolveHookFunc

type ResolveHookFunc func(context.Context, ResolveEvent)

ResolveHookFunc wraps a function as a ResolveHook.

func (ResolveHookFunc) OnResolve

func (fn ResolveHookFunc) OnResolve(ctx context.Context, event ResolveEvent)

OnResolve implements ResolveHook.

type ResolveOption

type ResolveOption func(*ResolveRequest)

ResolveOption mutates a resolve request.

func WithScopeChain added in v0.5.0

func WithScopeChain(chain ScopeChain) ResolveOption

WithScopeChain forces a specific scope chain instead of deriving it from context.

type ResolveRequest

type ResolveRequest struct {
	ScopeChain *ScopeChain
}

ResolveRequest captures optional inputs for a resolve call.

type ResolveSource

type ResolveSource string

ResolveSource captures which layer produced the final value.

const (
	ResolveSourceOverride ResolveSource = "override"
	ResolveSourceDefault  ResolveSource = "default"
	ResolveSourceFallback ResolveSource = "fallback"
)

type ResolveTrace

type ResolveTrace struct {
	Key               string
	NormalizedKey     string
	Chain             ScopeChain
	Value             bool
	Source            ResolveSource
	Override          OverrideTrace
	Default           DefaultTrace
	CacheHit          bool
	Strategy          string
	ClaimsFailureMode string
}

ResolveTrace captures provenance for a single feature resolution.

type ScopeChain added in v0.5.0

type ScopeChain []ScopeRef

ScopeChain is an ordered list of scope references.

type ScopeKind added in v0.5.0

type ScopeKind uint8

ScopeKind defines supported scope types.

const (
	ScopeSystem ScopeKind = iota
	ScopeTenant
	ScopeOrg
	ScopeUser
	ScopeRole
	ScopePerm
)

type ScopeRef added in v0.5.0

type ScopeRef struct {
	Kind     ScopeKind
	ID       string
	TenantID string
	OrgID    string
}

ScopeRef identifies a single scope target.

type TraceableFeatureGate

type TraceableFeatureGate interface {
	FeatureGate
	ResolveWithTrace(ctx context.Context, key string, opts ...ResolveOption) (bool, ResolveTrace, error)
}

TraceableFeatureGate adds explainability for feature resolution.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址