contextutil

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package contextutil discovers the EvaluationContext proto message and extracts dimension metadata for codegen backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverContextFromFiles added in v0.16.0

func DiscoverContextFromFiles(files *protoregistry.Files) (protoreflect.MessageDescriptor, error)

DiscoverContextFromFiles scans a file registry for a message annotated with option (pbflags.context). Returns the message descriptor, or an error if none or multiple are found. This is the runtime equivalent of DiscoverContext for use outside of protoc plugins (e.g., pbflags-sync).

func HasContextOption added in v0.16.0

func HasContextOption(opts protoreflect.ProtoMessage) bool

HasContextOption checks if the given message options contain the (pbflags.context) extension (field number 51003).

Types

type ContextDef

type ContextDef struct {
	MessageName string         // fully qualified message name
	Dimensions  []DimensionDef // dimensions in field-number order
	Message     *protogen.Message
}

ContextDef holds the discovered EvaluationContext message and its dimensions.

func DiscoverContext

func DiscoverContext(plugin *protogen.Plugin) (*ContextDef, error)

DiscoverContext scans all files in the plugin request for a message annotated with option (pbflags.context). Returns the context definition, or nil if none is found. Returns an error if multiple are found or if validation fails.

type DimensionDef

type DimensionDef struct {
	Name         string        // proto field name (e.g., "user_id")
	Number       int32         // proto field number
	Kind         DimensionKind // dimension type
	Description  string        // from DimensionOptions.description
	Distribution int32         // DimensionDistribution enum value (0=unspecified, 1=uniform, 2=categorical)
	Presence     int32         // DimensionPresence enum value (0=unspecified, 1=required, 2=optional)

	// Enum-specific metadata (only populated when Kind == DimensionEnum).
	EnumName   string          // fully qualified enum name
	EnumValues []EnumValueDef  // enum values
	ProtoField *protogen.Field // original protogen field for codegen access
}

DimensionDef describes a single dimension field in the EvaluationContext.

func (*DimensionDef) IsCategorical added in v0.18.0

func (d *DimensionDef) IsCategorical() bool

IsCategorical returns true if the dimension has distribution CATEGORICAL or is inherently categorical (enum/bool kind).

func (*DimensionDef) IsRequired added in v0.18.0

func (d *DimensionDef) IsRequired() bool

IsRequired returns true if the dimension has presence REQUIRED.

func (*DimensionDef) IsUniform added in v0.18.0

func (d *DimensionDef) IsUniform() bool

IsUniform returns true if the dimension has distribution UNIFORM (suitable for launch hashing).

type DimensionKind

type DimensionKind int

DimensionKind enumerates the supported proto types for context dimensions.

const (
	DimensionString DimensionKind = iota
	DimensionEnum
	DimensionBool
	DimensionInt64
)

func (DimensionKind) String

func (k DimensionKind) String() string

type EnumValueDef

type EnumValueDef struct {
	Name   string // proto enum value name (e.g., "PLAN_LEVEL_ENTERPRISE")
	Number int32  // ordinal
}

EnumValueDef describes a single enum value.

type ScopeDef added in v0.18.0

type ScopeDef struct {
	Name       string   // scope name (e.g., "anon", "user", "tenant")
	Dimensions []string // additional dimensions beyond globally required
}

ScopeDef describes a single evaluation scope.

func DiscoverScopes added in v0.18.0

func DiscoverScopes(plugin *protogen.Plugin) []ScopeDef

DiscoverScopes scans all files for (pbflags.scope) file-level options.

Jump to

Keyboard shortcuts

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