contextutil

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: 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
	Hashable    bool          // from DimensionOptions.hashable
	Bounded     bool          // from DimensionOptions.bounded

	// 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.

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.

Jump to

Keyboard shortcuts

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