flags

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flags is the single seam for runtime feature flags (design FF1/FF5). The rest of the app evaluates flags through this package, never through the OpenFeature SDK directly, so the provider is swappable and flags are trivially fakeable in tests.

The default provider is in-process and seeded from the environment at startup (FF2): it performs no network I/O, preserving the project's offline, fail-fast, 12-factor startup (design D10). A capability declares its flags as Definitions and passes them to New; New reads each flag's environment override, validates it, and fails fast on an invalid static value (FF7). Evaluation is fail-safe: any error returns the caller's in-code default rather than failing the request (FF4).

This is deliberately not a place for configuration. Endpoints, credentials, timeouts, and tuning stay environment configuration; only runtime behavioral toggles belong here (design FF3).

Index

Constants

View Source
const ProviderStatic = "static"

ProviderStatic is the default provider: an in-process store seeded from the environment. It is the only provider supported today; dynamic providers (e.g. flagd) are a future addition selected by the same setting.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Provider selects the flag backend; empty defaults to ProviderStatic.
	Provider string
	// Domain overrides the OpenFeature domain; empty uses the production default.
	Domain string
}

Config selects the provider and (for tests) the OpenFeature domain.

type Definition

type Definition struct {
	// Default is the value used when no environment override is set. Its dynamic
	// type MUST match Kind (bool for KindBool, string for KindString).
	Default any
	// Key is the dot-scoped flag key, e.g. "fallback.enabled".
	Key string
	// Env overrides the environment variable name; empty derives it from Key
	// (e.g. "fallback.enabled" -> "SCORECARD_FLAG_FALLBACK_ENABLED").
	Env string
	// Allowed optionally constrains a KindString flag to a set of values; an
	// override or default outside the set fails validation at startup.
	Allowed []string
	// Kind is the flag's value type.
	Kind Kind
}

Definition declares a single flag a capability owns (design FF6). It is passed to New, which reads the flag's environment override, validates it, and seeds the provider. Field order favors pointer packing (govet fieldalignment).

type Flags

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

Flags evaluates feature flags through the configured provider.

func New

func New(getenv func(string) string, cfg Config, defs ...Definition) (*Flags, error)

New builds a Flags over the selected provider, seeding it from the given definitions and their environment overrides. It returns an error on an unknown provider or an invalid static flag value (design FF7), so the server fails fast at startup rather than serving with a misconfigured flag.

func (*Flags) Bool

func (f *Flags) Bool(ctx context.Context, key string, def bool) bool

Bool evaluates a boolean flag, returning def on any evaluation error (FF4).

func (*Flags) String

func (f *Flags) String(ctx context.Context, key, def string) string

String evaluates a string flag, returning def on any evaluation error (FF4).

type Kind

type Kind int

Kind is the value type of a flag.

const (
	// KindBool is a boolean on/off toggle.
	KindBool Kind = iota
	// KindString is a string, optionally constrained to an allowed set.
	KindString
)

Jump to

Keyboard shortcuts

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