pbflags

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pbflags provides core types for the pbflags evaluation context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWith

func ContextWith(ctx context.Context, eval Evaluator) context.Context

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

func Connect(httpClient *http.Client, url string, contextMsg proto.Message) Evaluator

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

func FromContext(ctx context.Context) Evaluator

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

func BoolListOverride(flagID string, vals ...bool) Override

BoolListOverride creates an override that sets a bool list flag.

func BoolOverride added in v0.19.0

func BoolOverride(flagID string, val bool) Override

BoolOverride creates an override that sets a bool flag.

func DoubleListOverride added in v0.19.0

func DoubleListOverride(flagID string, vals ...float64) Override

DoubleListOverride creates an override that sets a float64 list flag.

func DoubleOverride added in v0.19.0

func DoubleOverride(flagID string, val float64) Override

DoubleOverride creates an override that sets a float64 flag.

func Int64ListOverride added in v0.19.0

func Int64ListOverride(flagID string, vals ...int64) Override

Int64ListOverride creates an override that sets an int64 list flag.

func Int64Override added in v0.19.0

func Int64Override(flagID string, val int64) Override

Int64Override creates an override that sets an int64 flag.

func StringListOverride added in v0.19.0

func StringListOverride(flagID string, vals ...string) Override

StringListOverride creates an override that sets a string list flag.

func StringOverride added in v0.19.0

func StringOverride(flagID string, val string) Override

StringOverride creates an override that sets a string flag.

func (Override) FlagID added in v0.19.0

func (o Override) FlagID() string

FlagID returns the flag ID this override targets.

func (Override) Value added in v0.19.0

func (o Override) Value() *pbflagsv1.FlagValue

Value returns the override's flag value.

type Result

type Result struct {
	Value  *pbflagsv1.FlagValue
	Source pbflagsv1.EvaluationSource
}

Result holds the outcome of a single flag evaluation.

Jump to

Keyboard shortcuts

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