featureflagscfg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package featureflagscfg selects and builds a featureflags.FeatureFlagManager from configuration: LaunchDarkly, PostHog, or the noop manager.

The two vendor providers differ only in construction and shutdown — both evaluate through the same OpenFeature client underneath — so the choice here is about which service holds the flags rather than about how they are read. The noop manager answers every flag with the default the caller passed, which is why it has to be named: it is indistinguishable from a rollout that has not started.

The *http.Client is a dependency rather than an option, so the transport the vendor SDK uses stays the deployment's to configure.

Index

Constants

View Source
const (
	// ProviderLaunchDarkly is used to indicate the LaunchDarkly provider.
	ProviderLaunchDarkly = "launchdarkly"
	// ProviderPostHog is used to indicate the PostHog provider.
	ProviderPostHog = "posthog"
	// ProviderNoop reports every flag as its default. It must be selected
	// deliberately — an unset or typo'd provider is an error, because a manager
	// that silently answers "off" for everything looks like a quiet rollout.
	ProviderNoop = "noop"
)

Variables

This section is empty.

Functions

func NewFeatureFlagManager

func NewFeatureFlagManager(ctx context.Context, c *Config, httpClient *http.Client, opts ...Option) (featureflags.FeatureFlagManager, error)

NewFeatureFlagManager provides a FeatureFlagManager from config.

func RegisterFeatureFlagManager

func RegisterFeatureFlagManager(i do.Injector)

RegisterFeatureFlagManager registers a featureflags.FeatureFlagManager with the injector.

Types

type Config

type Config struct {
	LaunchDarkly   *launchdarkly.Config      `env:",init"    envPrefix:"LAUNCH_DARKLY_"    json:"launchDarkly,omitempty"        yaml:"launchDarkly,omitempty"`
	PostHog        *posthog.Config           `env:",init"    envPrefix:"POSTHOG_"          json:"posthog,omitempty"             yaml:"posthog,omitempty"`
	Provider       string                    `env:"PROVIDER" json:"provider,omitempty"     yaml:"provider,omitempty"`
	CircuitBreaker circuitbreakingcfg.Config `env:",init"    envPrefix:"CIRCUIT_BREAKING_" json:"circuitBreakerConfig,omitzero" yaml:"circuitBreakerConfig,omitempty"`
}

Config configures our feature flag manager.

func (*Config) EnsureDefaults

func (cfg *Config) EnsureDefaults()

EnsureDefaults sets sensible defaults for zero-valued fields.

func (*Config) NewFeatureFlagManager

func (c *Config) NewFeatureFlagManager(ctx context.Context, httpClient *http.Client, circuitBreaker circuitbreaking.CircuitBreaker, opts ...Option) (featureflags.FeatureFlagManager, error)

NewFeatureFlagManager builds the configured feature flag manager.

Each provider is built into a variable and returned only once its error is known to be nil. The provider constructors return their own concrete types, so returning one straight through would convert a nil *launchdarkly.FeatureFlagManager into a non-nil featureflags.FeatureFlagManager on the error path, and a caller testing the result against nil would find a manager that panics on first use.

func (*Config) ValidateWithContext

func (c *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates the config.

type Option

type Option func(*options)

Option configures how NewFeatureFlagManager assembles its manager.

The observability dependencies are options rather than parameters because every one of them is genuinely optional: an absent logger logs nowhere, an absent tracer provider traces nowhere, and an absent metrics provider records nothing. Requiring them positionally made a caller that wanted none of the three name all three anyway, usually as noops.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger. An absent logger logs nowhere.

func WithMetricsProvider

func WithMetricsProvider(metricsProvider metrics.Provider) Option

WithMetricsProvider attaches a metrics provider. An absent provider records nothing.

func WithPillars

func WithPillars(p *observability.Pillars) Option

WithPillars attaches a logger, tracer provider, and metrics provider in one go, for the common case where a caller has already built them together. A nil Pillars attaches nothing.

It is applied in order with the individual options, so a caller can hand over its pillars and then override one of them.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.Provider) Option

WithTracerProvider attaches a tracer provider, enabling spans on the instrumented operations. An absent tracer provider traces nowhere.

Jump to

Keyboard shortcuts

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