Documentation
¶
Index ¶
- Constants
- func Bucket(flagName, targetingKey string) int
- func Decide(f Flag, ctx EvalContext, key string) (on, ruleHit bool)
- func InRollout(flagName, targetingKey string, rollout int) bool
- func MatchRules(rules []Rule, ctx EvalContext) (serve, matched bool)
- func ValidFlagName(name string) bool
- func ValidateRules(rules []Rule) error
- type APIKeyClaims
- type APIKeyHTTPSystem
- type APIKeySystem
- type AgentResponse
- type BulkEvaluationRequest
- type BulkEvaluationResponse
- type CompanyFlagEntry
- type CompanyFlagEnvironment
- type Details
- type ErrorCode
- type ErrorEvaluationResponse
- type EvalContext
- type EvaluationContext
- type EvaluationRequest
- type Flag
- type FlagNameChangeRequest
- type GenerateAPIKeyRequest
- type GenerateAPIKeyResponse
- type OFREPSystem
- type ResolutionReason
- type Response
- type Rule
- type SecretMenu
- type SecretMenuStyle
- type SuccessEvaluationResponse
- type System
- func (s *System) CreateFlagInDB(ctx context.Context, flag flagCreate) error
- func (s *System) CreateFlags(w http.ResponseWriter, r *http.Request)
- func (s *System) DeleteAllFlagsForEnv(ctx context.Context, envId string) error
- func (s *System) DeleteFlagFromDB(ctx context.Context, flag Flag) error
- func (s *System) DeleteFlags(w http.ResponseWriter, r *http.Request)
- func (s *System) EditFlag(w http.ResponseWriter, r *http.Request)
- func (s *System) EditFlagInDB(ctx context.Context, cr FlagNameChangeRequest) error
- func (s *System) GetAgentFlags(w http.ResponseWriter, r *http.Request)
- func (s *System) GetAgentFlagsFromDB(ctx context.Context, projectId, agentId, environmentId string) (*AgentResponse, error)
- func (s *System) GetClientFlags(w http.ResponseWriter, r *http.Request)
- func (s *System) GetClientFlagsFromDB(ctx context.Context, environmentId string) ([]Flag, error)
- func (s *System) GetCompanyFlagsFromDB(ctx context.Context, companyId string) ([]CompanyFlagEntry, error)
- func (s *System) GetDefaultEnvironment(ctx context.Context, projectId, agentId string) (string, error)
- func (s *System) PromoteFlag(w http.ResponseWriter, r *http.Request)
- func (s *System) PromoteFlagInDB(ctx context.Context, flagId string) error
- func (s *System) SetRollout(w http.ResponseWriter, r *http.Request)
- func (s *System) SetRolloutInDB(ctx context.Context, flagId string, rollout int) error
- func (s *System) SetRules(w http.ResponseWriter, r *http.Request)
- func (s *System) SetRulesInDB(ctx context.Context, flagId string, rules []Rule) error
- func (s *System) UpdateFlagInDB(ctx context.Context, flag Flag) error
- func (s *System) UpdateFlags(w http.ResponseWriter, r *http.Request)
Constants ¶
const ContextHeader = "x-flags-context"
const RolloutCapability = "rollout"
RolloutCapability is the x-flags-capabilities value an SDK sends when it evaluates rollouts itself.
Variables ¶
This section is empty.
Functions ¶
func Bucket ¶ added in v0.16.1
Bucket places a visitor in 0..99 for a flag. Every SDK must compute exactly this: FNV-1a 32-bit of "<flag name>:<targeting key>", modulo 100.
func Decide ¶ added in v0.16.1
func Decide(f Flag, ctx EvalContext, key string) (on, ruleHit bool)
Decide is what one user is served: off when disabled, else the first matching rule, else the rollout.
func InRollout ¶ added in v0.16.1
InRollout reports whether the visitor sees an enabled flag with this rollout percentage. Without a targeting key only a full rollout applies, so partial rollouts fail closed.
func MatchRules ¶ added in v0.16.1
func MatchRules(rules []Rule, ctx EvalContext) (serve, matched bool)
MatchRules returns the first matching rule's Serve value.
func ValidFlagName ¶ added in v0.15.3
func ValidateRules ¶ added in v0.16.1
ValidateRules bounds what the dashboard can store.
Types ¶
type APIKeyClaims ¶ added in v0.14.7
type APIKeyClaims struct {
ProjectID string `json:"project_id"`
AgentID string `json:"agent_id"`
EnvironmentID string `json:"environment_id,omitempty"`
jwt.RegisteredClaims
}
APIKeyClaims represents the JWT claims for an API key
type APIKeyHTTPSystem ¶ added in v0.14.7
type APIKeyHTTPSystem struct {
Config *ConfigBuilder.Config
}
func NewAPIKeyHTTPSystem ¶ added in v0.14.7
func NewAPIKeyHTTPSystem(cfg *ConfigBuilder.Config) *APIKeyHTTPSystem
func (*APIKeyHTTPSystem) GenerateAPIKeyHandler ¶ added in v0.14.7
func (s *APIKeyHTTPSystem) GenerateAPIKeyHandler(w http.ResponseWriter, r *http.Request)
GenerateAPIKeyHandler handles POST /api-key/generate
type APIKeySystem ¶ added in v0.14.7
type APIKeySystem struct {
Config *ConfigBuilder.Config
}
APIKeySystem handles API key generation and validation
func NewAPIKeySystem ¶ added in v0.14.7
func NewAPIKeySystem(cfg *ConfigBuilder.Config) *APIKeySystem
func (*APIKeySystem) GenerateAPIKey ¶ added in v0.14.7
func (s *APIKeySystem) GenerateAPIKey(projectID, agentID, environmentID string) (string, error)
GenerateAPIKey creates a JWT-based API key with project, agent, and environment info
func (*APIKeySystem) ValidateAPIKey ¶ added in v0.14.7
func (s *APIKeySystem) ValidateAPIKey(tokenString string) (*APIKeyClaims, error)
ValidateAPIKey parses and validates a JWT-based API key
type AgentResponse ¶
type AgentResponse struct {
IntervalAllowed int `json:"intervalAllowed,omitempty"`
SecretMenu SecretMenu `json:"secretMenu,omitempty"`
Flags []Flag `json:"flags,omitempty"`
}
type BulkEvaluationRequest ¶ added in v0.14.7
type BulkEvaluationRequest struct {
Context EvaluationContext `json:"context,omitempty"`
}
BulkEvaluationRequest is for evaluating multiple flags
type BulkEvaluationResponse ¶ added in v0.14.7
type BulkEvaluationResponse struct {
Flags []interface{} `json:"flags"`
}
BulkEvaluationResponse wraps multiple flag evaluations
type CompanyFlagEntry ¶ added in v0.15.0
type CompanyFlagEntry struct {
Flag Flag `json:"flag"`
Environment CompanyFlagEnvironment `json:"environment"`
}
type CompanyFlagEnvironment ¶ added in v0.15.0
type ErrorEvaluationResponse ¶ added in v0.14.7
type ErrorEvaluationResponse struct {
Key string `json:"key"`
ErrorCode ErrorCode `json:"errorCode"`
ErrorDetails string `json:"errorDetails,omitempty"`
Reason ResolutionReason `json:"reason"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ErrorEvaluationResponse represents a failed flag evaluation
type EvalContext ¶ added in v0.16.1
EvalContext is what an SDK knows about the user: "key" is the targeting key, other attributes are strings or lists of strings (e.g. "groups": ["beta", "staff"]).
func ParseContextHeader ¶ added in v0.16.1
func ParseContextHeader(h string) (EvalContext, error)
ParseContextHeader decodes the base64(JSON object) an SDK sends in x-flags-context.
type EvaluationContext ¶ added in v0.14.7
type EvaluationContext struct {
TargetingKey string `json:"targetingKey,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
}
EvaluationContext represents the context for flag evaluation. Per the OFREP spec, attributes sit flat next to targetingKey; a nested "context" object is also accepted for older callers.
func (*EvaluationContext) UnmarshalJSON ¶ added in v0.16.1
func (e *EvaluationContext) UnmarshalJSON(b []byte) error
type EvaluationRequest ¶ added in v0.14.7
type EvaluationRequest struct {
Context EvaluationContext `json:"context,omitempty"`
}
EvaluationRequest is the request body for flag evaluation
type Flag ¶
type Flag struct {
Enabled bool `json:"enabled"`
Details Details `json:"details"`
// Rollout is the percentage of visitors that see an enabled flag; omitted (nil) means 100.
Rollout *int `json:"rollout,omitempty"`
// Rules are evaluated on the server and never sent to SDKs.
Rules []Rule `json:"-"`
}
type FlagNameChangeRequest ¶
type GenerateAPIKeyRequest ¶ added in v0.14.7
type GenerateAPIKeyResponse ¶ added in v0.14.7
type OFREPSystem ¶ added in v0.14.7
type OFREPSystem struct {
Config *ConfigBuilder.Config
}
OFREPSystem handles OFREP endpoints
func NewOFREPSystem ¶ added in v0.14.7
func NewOFREPSystem(cfg *ConfigBuilder.Config) *OFREPSystem
func (*OFREPSystem) EvaluateBulkFlags ¶ added in v0.14.7
func (s *OFREPSystem) EvaluateBulkFlags(w http.ResponseWriter, r *http.Request)
EvaluateBulkFlags handles POST /ofrep/v1/evaluate/flags
func (*OFREPSystem) EvaluateSingleFlag ¶ added in v0.14.7
func (s *OFREPSystem) EvaluateSingleFlag(w http.ResponseWriter, r *http.Request)
EvaluateSingleFlag handles POST /ofrep/v1/evaluate/flags/{key}
func (*OFREPSystem) GetSingleFlagFromDB ¶ added in v0.14.7
type ResolutionReason ¶ added in v0.14.7
type ResolutionReason string
ResolutionReason represents why a flag was resolved to its value
const ( ReasonStatic ResolutionReason = "STATIC" ReasonSplit ResolutionReason = "SPLIT" ReasonTargetingMatch ResolutionReason = "TARGETING_MATCH" ReasonDefault ResolutionReason = "DEFAULT" ReasonDisabled ResolutionReason = "DISABLED" ReasonError ResolutionReason = "ERROR" ReasonUnknown ResolutionReason = "UNKNOWN" )
type Rule ¶ added in v0.16.1
type Rule struct {
Attribute string `json:"attribute"`
Operator string `json:"operator"`
Values []string `json:"values"`
Serve bool `json:"serve"`
}
Rule targets users by an attribute of their evaluation context. Rules are checked in order and the first match decides the flag (Serve); with no match the flag's rollout applies. Matching ignores case.
func (Rule) Matches ¶ added in v0.16.1
func (r Rule) Matches(ctx EvalContext) bool
Matches reports whether any of the user's values for the attribute matches any rule value. not_in matches when the user has the attribute and none of its values is listed. A user without the attribute never matches, whatever the operator.
type SecretMenu ¶
type SecretMenu struct {
Sequence []string `json:"sequence,omitempty"`
Styles []SecretMenuStyle `json:"styles,omitempty"`
}
type SecretMenuStyle ¶
type SuccessEvaluationResponse ¶ added in v0.14.7
type SuccessEvaluationResponse struct {
Key string `json:"key"`
Reason ResolutionReason `json:"reason"`
Variant string `json:"variant,omitempty"`
Value interface{} `json:"value"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
SuccessEvaluationResponse represents a successful flag evaluation
type System ¶
type System struct {
Config *ConfigBuilder.Config
}
func NewSystem ¶
func NewSystem(cfg *ConfigBuilder.Config) *System
func (*System) CreateFlagInDB ¶
func (*System) CreateFlags ¶
func (s *System) CreateFlags(w http.ResponseWriter, r *http.Request)
func (*System) DeleteAllFlagsForEnv ¶
func (*System) DeleteFlagFromDB ¶
func (*System) DeleteFlags ¶
func (s *System) DeleteFlags(w http.ResponseWriter, r *http.Request)
func (*System) EditFlagInDB ¶
func (s *System) EditFlagInDB(ctx context.Context, cr FlagNameChangeRequest) error
func (*System) GetAgentFlags ¶
func (s *System) GetAgentFlags(w http.ResponseWriter, r *http.Request)
func (*System) GetAgentFlagsFromDB ¶
func (*System) GetClientFlags ¶
func (s *System) GetClientFlags(w http.ResponseWriter, r *http.Request)
func (*System) GetClientFlagsFromDB ¶
func (*System) GetCompanyFlagsFromDB ¶ added in v0.15.0
func (*System) GetDefaultEnvironment ¶
func (*System) PromoteFlag ¶ added in v0.14.7
func (s *System) PromoteFlag(w http.ResponseWriter, r *http.Request)
func (*System) PromoteFlagInDB ¶ added in v0.14.7
func (*System) SetRollout ¶ added in v0.16.1
func (s *System) SetRollout(w http.ResponseWriter, r *http.Request)
SetRollout: PATCH /flag/{flagId}/rollout {"rollout": 0-100}
func (*System) SetRolloutInDB ¶ added in v0.16.1
SetRolloutInDB sets the percentage of visitors that see the flag when it is enabled.
func (*System) SetRules ¶ added in v0.16.1
func (s *System) SetRules(w http.ResponseWriter, r *http.Request)
SetRules: PUT /flag/{flagId}/rules {"rules": [...]} replaces the flag's targeting rules in its environment.
func (*System) SetRulesInDB ¶ added in v0.16.1
SetRulesInDB replaces the flag's targeting rules.
func (*System) UpdateFlagInDB ¶
func (*System) UpdateFlags ¶
func (s *System) UpdateFlags(w http.ResponseWriter, r *http.Request)