Help us shape the future of Go! Take the 2026 Go Developer Survey

feature

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package feature implements the config-driven feature flag and canary rollout provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseEvalContextFromHeader

func ParseEvalContextFromHeader(getHeader func(string) string) featurecontract.EvaluationContext

ParseEvalContextFromHeader constructs EvaluationContext from HTTP headers (X-User-ID, X-Tenant-ID).

Types

type FlagRule

type FlagRule struct {
	Enabled         bool           `mapstructure:"enabled" json:"enabled"`
	DefaultValue    any            `mapstructure:"default_value" json:"default_value"`
	UserWhitelist   []string       `mapstructure:"user_whitelist" json:"user_whitelist"`
	TenantWhitelist []string       `mapstructure:"tenant_whitelist" json:"tenant_whitelist"`
	Percentage      int            `mapstructure:"percentage" json:"percentage"` // 0 - 100
	ValueMap        map[string]any `mapstructure:"value_map" json:"value_map"`
}

FlagRule defines the configuration rule for a single feature flag.

type Provider

type Provider struct {
	Service *Service
}

Provider is the DI provider for feature flag capabilities.

func NewProvider

func NewProvider(initialFlags ...map[string]FlagRule) *Provider

NewProvider creates a new feature Provider instance.

func (*Provider) Boot

Boot initializes the provider.

func (*Provider) Register

func (p *Provider) Register(c runtimecontract.Container) error

Register binds FeatureKey in the DI container.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the in-memory/config-backed FeatureManager implementation.

func NewService

func NewService(initialFlags ...map[string]FlagRule) *Service

NewService creates a new feature flag Service with initial flag rules.

func (*Service) EvaluateBool

func (s *Service) EvaluateBool(ctx context.Context, flagKey string, defaultVal bool, evalCtx featurecontract.EvaluationContext) bool

EvaluateBool evaluates a boolean feature flag.

func (*Service) EvaluateInt

func (s *Service) EvaluateInt(ctx context.Context, flagKey string, defaultVal int, evalCtx featurecontract.EvaluationContext) int

EvaluateInt evaluates an integer feature flag.

func (*Service) EvaluateJSON

func (s *Service) EvaluateJSON(ctx context.Context, flagKey string, out any, evalCtx featurecontract.EvaluationContext) error

EvaluateJSON evaluates a JSON object feature flag into target out.

func (*Service) EvaluateString

func (s *Service) EvaluateString(ctx context.Context, flagKey string, defaultVal string, evalCtx featurecontract.EvaluationContext) string

EvaluateString evaluates a string feature flag.

func (*Service) SetRule

func (s *Service) SetRule(flagKey string, rule FlagRule)

SetRule sets or updates a feature flag rule dynamically.

Jump to

Keyboard shortcuts

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