Documentation
¶
Overview ¶
Package pbflags provides core types for the pbflags evaluation context.
Index ¶
- func ContextWith(ctx context.Context, eval Evaluator) context.Context
- func ValidateOverrides(overrides []Override, descriptors []flagmeta.FlagDescriptor) error
- type Dimension
- type Evaluator
- type Override
- func BoolListOverride(flagID string, vals ...bool) Override
- func BoolOverride(flagID string, val bool) Override
- func DoubleListOverride(flagID string, vals ...float64) Override
- func DoubleOverride(flagID string, val float64) Override
- func Int64ListOverride(flagID string, vals ...int64) Override
- func Int64Override(flagID string, val int64) Override
- func StringListOverride(flagID string, vals ...string) Override
- func StringOverride(flagID string, val string) Override
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWith ¶
ContextWith stores an Evaluator in a context.Context. Panics if eval is nil.
func ValidateOverrides ¶ added in v0.19.0
func ValidateOverrides(overrides []Override, descriptors []flagmeta.FlagDescriptor) error
ValidateOverrides checks that each override's value type matches the flag definition in descriptors. Returns an error listing all mismatches. An override targeting a flag ID not present in descriptors is an error.
Types ¶
type Dimension ¶
type Dimension interface {
// Apply sets this dimension's value on the given proto message.
// The message must be the EvaluationContext type. Apply silently
// does nothing if the named field does not exist on the message
// or if the field's proto kind does not match the dimension type.
Apply(msg protoreflect.Message)
}
Dimension represents a single key-value pair in an evaluation context. Implementations set a named field on the EvaluationContext proto message via protoreflect. Generated dimension constructors (in the dims package) return Dimension values; application code should not implement this interface directly.
func BoolDimension ¶
func BoolDimension(name protoreflect.Name, val bool) Dimension
BoolDimension creates a Dimension that sets a bool field.
func EnumDimension ¶
func EnumDimension(name protoreflect.Name, val protoreflect.EnumNumber) Dimension
EnumDimension creates a Dimension that sets an enum field by ordinal.
func Int64Dimension ¶
func Int64Dimension(name protoreflect.Name, val int64) Dimension
Int64Dimension creates a Dimension that sets an int64 field.
func StringDimension ¶
func StringDimension(name protoreflect.Name, val string) Dimension
StringDimension creates a Dimension that sets a string field.
type Evaluator ¶
type Evaluator interface {
// With returns a new Evaluator with additional context dimensions bound.
// Dimensions from the parent are preserved; new dimensions override
// any existing dimension with the same name.
With(dims ...Dimension) Evaluator
// Evaluate resolves a single flag against the bound context.
// Called by generated client code — not typically called directly.
Evaluate(ctx context.Context, flagID string) (*Result, error)
// BulkEvaluate resolves multiple flags against the bound context.
BulkEvaluate(ctx context.Context, flagIDs []string) ([]*Result, error)
}
Evaluator provides flag evaluation with bound context dimensions. Evaluators are immutable — With() returns a new Evaluator, it does not modify the receiver.
func Connect ¶
Connect creates an Evaluator backed by a FlagEvaluatorService at the given URL. contextMsg is a zero-value instance of the customer's EvaluationContext proto (e.g., &examplepb.EvaluationContext{}). It is used as a prototype for creating new context messages during evaluation.
func FromContext ¶
FromContext retrieves the Evaluator from a context.Context. Returns a no-op evaluator (all compiled defaults) if none is set or if the stored value is a typed-nil.
func WithOverrides ¶ added in v0.19.0
func WithOverrides(eval Evaluator, descriptors []flagmeta.FlagDescriptor, overrides ...Override) Evaluator
WithOverrides wraps an Evaluator so that the specified flags return hard-coded values without hitting the evaluation server. Non-overridden flags delegate to the underlying evaluator.
This function is intended for use in tests. Overrides are preserved across [Evaluator.With] calls — adding dimensions does not discard them.
If descriptors is non-nil, each override is validated against the flag definitions: unknown flag IDs and type mismatches cause a panic. Pass nil to skip validation.
Panics if eval is nil or if any override fails validation.
type Override ¶ added in v0.19.0
type Override struct {
// contains filtered or unexported fields
}
Override pairs a flag ID with a type-safe value for use with WithOverrides.
func BoolListOverride ¶ added in v0.19.0
BoolListOverride creates an override that sets a bool list flag.
func BoolOverride ¶ added in v0.19.0
BoolOverride creates an override that sets a bool flag.
func DoubleListOverride ¶ added in v0.19.0
DoubleListOverride creates an override that sets a float64 list flag.
func DoubleOverride ¶ added in v0.19.0
DoubleOverride creates an override that sets a float64 flag.
func Int64ListOverride ¶ added in v0.19.0
Int64ListOverride creates an override that sets an int64 list flag.
func Int64Override ¶ added in v0.19.0
Int64Override creates an override that sets an int64 flag.
func StringListOverride ¶ added in v0.19.0
StringListOverride creates an override that sets a string list flag.
func StringOverride ¶ added in v0.19.0
StringOverride creates an override that sets a string flag.