flags

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ContextHeader = "x-flags-context"
View Source
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

func Bucket(flagName, targetingKey string) int

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

func InRollout(flagName, targetingKey string, rollout int) bool

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 ValidFlagName(name string) bool

func ValidateRules added in v0.16.1

func ValidateRules(rules []Rule) error

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 CompanyFlagEnvironment struct {
	Id            string `json:"id"`
	Name          string `json:"name"`
	EnvironmentId string `json:"environment_id"`
	AgentId       string `json:"agent_id"`
	AgentName     string `json:"agent_name,omitempty"`
	ProjectName   string `json:"project_name,omitempty"`
}

type Details

type Details struct {
	Name        string `json:"name"`
	ID          string `json:"id"`
	LastChanged string `json:"lastChanged,omitempty"`
	Promoted    bool   `json:"promoted,omitempty"`
}

type ErrorCode added in v0.14.7

type ErrorCode string

ErrorCode represents OFREP error codes

const (
	ErrorParseError          ErrorCode = "PARSE_ERROR"
	ErrorTargetingKeyMissing ErrorCode = "TARGETING_KEY_MISSING"
	ErrorInvalidContext      ErrorCode = "INVALID_CONTEXT"
	ErrorFlagNotFound        ErrorCode = "FLAG_NOT_FOUND"
	ErrorTypeMismatch        ErrorCode = "TYPE_MISMATCH"
	ErrorGeneral             ErrorCode = "GENERAL"
)

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

type EvalContext map[string]any

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 FlagNameChangeRequest struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

type GenerateAPIKeyRequest added in v0.14.7

type GenerateAPIKeyRequest struct {
	ProjectID     string `json:"project_id"`
	AgentID       string `json:"agent_id"`
	EnvironmentID string `json:"environment_id,omitempty"`
}

type GenerateAPIKeyResponse added in v0.14.7

type GenerateAPIKeyResponse struct {
	APIKey    string `json:"api_key"`
	ExpiresAt string `json:"expires_at"`
}

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

func (s *OFREPSystem) GetSingleFlagFromDB(ctx context.Context, projectId, agentId, environmentId, flagKey string) (*Flag, error)

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 Response

type Response struct {
	Flags []Flag `json:"flags"`
}

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 SecretMenuStyle struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

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 (s *System) CreateFlagInDB(ctx context.Context, flag flagCreate) error

func (*System) CreateFlags

func (s *System) CreateFlags(w http.ResponseWriter, r *http.Request)

func (*System) DeleteAllFlagsForEnv

func (s *System) DeleteAllFlagsForEnv(ctx context.Context, envId string) error

func (*System) DeleteFlagFromDB

func (s *System) DeleteFlagFromDB(ctx context.Context, flag Flag) error

func (*System) DeleteFlags

func (s *System) DeleteFlags(w http.ResponseWriter, r *http.Request)

func (*System) EditFlag

func (s *System) EditFlag(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 (s *System) GetAgentFlagsFromDB(ctx context.Context, projectId, agentId, environmentId string) (*AgentResponse, error)

func (*System) GetClientFlags

func (s *System) GetClientFlags(w http.ResponseWriter, r *http.Request)

func (*System) GetClientFlagsFromDB

func (s *System) GetClientFlagsFromDB(ctx context.Context, environmentId string) ([]Flag, error)

func (*System) GetCompanyFlagsFromDB added in v0.15.0

func (s *System) GetCompanyFlagsFromDB(ctx context.Context, companyId string) ([]CompanyFlagEntry, error)

func (*System) GetDefaultEnvironment

func (s *System) GetDefaultEnvironment(ctx context.Context, projectId, agentId string) (string, error)

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 (s *System) PromoteFlagInDB(ctx context.Context, flagId string) error

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

func (s *System) SetRolloutInDB(ctx context.Context, flagId string, rollout int) error

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

func (s *System) SetRulesInDB(ctx context.Context, flagId string, rules []Rule) error

SetRulesInDB replaces the flag's targeting rules.

func (*System) UpdateFlagInDB

func (s *System) UpdateFlagInDB(ctx context.Context, flag Flag) error

func (*System) UpdateFlags

func (s *System) UpdateFlags(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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