config

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config parses the WAVEFRONT_* environment once at startup into an immutable Config. Required vars missing ⇒ MissingError; malformed values ⇒ InvalidError (both name the offending var). Load uses the functional-options pattern: production calls config.Load(); tests inject a fixed environment with config.Load(config.WithLookup(fake)).

Recognised environment variables:

WAVEFRONT_BUNDLE_PATH             — path to the bundle directory (required)
WAVEFRONT_UPSTREAM_BASE_URL       — default backend base URL (required)
WAVEFRONT_TARGETS                 — named backend targets, comma-separated name=url pairs
WAVEFRONT_LISTEN_ADDR             — data-plane listen address (default 0.0.0.0:8080)
WAVEFRONT_METRICS_ADDR            — ops/metrics listen address (default 0.0.0.0:9090)
WAVEFRONT_CONTRACT_VERSION_HEADER — header carrying the contract version (default X-Api-Contract-Version)
WAVEFRONT_REQUEST_TIMEOUT_MS      — per-request upstream timeout in ms (default 15000)
WAVEFRONT_READ_HEADER_TIMEOUT_MS  — data-plane ReadHeaderTimeout in ms (default 10000)
WAVEFRONT_READ_TIMEOUT_MS         — data-plane ReadTimeout (headers+body) in ms (default 30000)
WAVEFRONT_MAX_BODY_BYTES          — maximum request body size in bytes (default 1048576)
WAVEFRONT_LOG_LEVEL               — log level: debug|info|warn|error (default info)
WAVEFRONT_TRACES_OTLP_ENDPOINT    — OTLP/HTTP collector base URL; unset disables tracing
WAVEFRONT_TRACES_SERVICE_NAME     — resource service.name on emitted spans (default wavefront)
WAVEFRONT_TRACES_SAMPLE_RATIO     — root-trace sample probability in (0,1] (default 1)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpsAddr added in v0.7.3

func OpsAddr(opts ...Option) string

OpsAddr resolves the ops/metrics listen address exactly as Load does — WAVEFRONT_METRICS_ADDR, or its default when unset/blank — without touching the rest of the configuration. The container self-probe uses it: a probe must reach the same configured ops port the server bound, and must not fail because serving-only required vars (bundle path, upstream URL) are absent. No validation: a malformed value simply fails the probe's dial, which is the correct healthcheck outcome.

Types

type Config

type Config struct {
	BundlePath            string
	UpstreamBaseURL       string
	Targets               map[string]string
	ListenAddr            string
	MetricsAddr           string
	ContractVersionHeader string
	RequestTimeout        time.Duration
	ReadHeaderTimeout     time.Duration
	ReadTimeout           time.Duration
	MaxBodyBytes          int64
	LogLevel              slog.Level
	TracesEndpoint        string
	TracesServiceName     string
	TracesSampleRatio     float64
}

func Load

func Load(opts ...Option) (*Config, error)

Load parses the WAVEFRONT_* environment once into an immutable Config. Production: config.Load(). Tests: config.Load(config.WithLookup(fake)).

func (*Config) TargetURL added in v0.3.0

func (c *Config) TargetURL(name string) (string, bool)

TargetURL returns the base URL for a named backend target. The empty name resolves to the default target (UpstreamBaseURL). An unknown name returns ("", false).

type InvalidError

type InvalidError struct {
	Var   string
	Value string
	Err   error
}

func (*InvalidError) Error

func (e *InvalidError) Error() string

func (*InvalidError) Unwrap

func (e *InvalidError) Unwrap() error

type Lookuper

type Lookuper func(key string) (string, bool)

Lookuper resolves an environment variable: its value and whether it is set. It matches the signature of os.LookupEnv.

type MissingError

type MissingError struct{ Var string }

func (*MissingError) Error

func (e *MissingError) Error() string

type Option

type Option func(*loader)

Option configures Load.

func WithLookup

func WithLookup(fn Lookuper) Option

WithLookup overrides the environment source (default os.LookupEnv). Tests use it to supply a fixed, in-memory environment.

Jump to

Keyboard shortcuts

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