pbflags

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 10 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.

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.

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