config

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides a factory for ConfigLoader implementations with multiple backends.

Use New() or NewFromConfig() to create a loaded config instance. The factory handles calling Load() internally, returning a ready-to-use ConfigLoader.

Example:

// Create a Viper config loader pointing at a config directory
cfg, err := config.New(config.KindViper, config.WithBaseDir("./configs"))
if err != nil {
    log.Fatal(err)
}
port := cfg.GetInt("server.port")

// Create from config struct
c := config.DefaultConfig()
c.Viper.BaseDir = "./configs"
cfg, err := config.NewFromConfig(c)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(kind Kind, opts ...options.Option[Config]) (interfaces.ConfigLoader, error)

New creates a ConfigLoader of the specified kind with optional functional options. The loader is fully initialized (Load called internally). Returns an error if the kind is unknown or loading fails.

Example:

cfg, err := config.New(config.KindViper, config.WithBaseDir("./configs"))
if err != nil {
    return err
}
port := cfg.GetInt("server.port")

func NewFromConfig

func NewFromConfig(cfg Config) (interfaces.ConfigLoader, error)

NewFromConfig creates a ConfigLoader from a Config struct. The loader is fully initialized (Load called internally). Returns an error if the kind is unknown or loading fails.

func WithBaseDir

func WithBaseDir(dir string) options.Option[Config]

WithBaseDir sets the directory containing config files.

func WithEnvPrefix

func WithEnvPrefix(prefix string) options.Option[Config]

WithEnvPrefix sets the prefix for environment variable binding (default: none). Set one: with no prefix, env vars are read by their bare names, which collide with the <SVC>_PORT / <SVC>_SERVICE_HOST variables Kubernetes injects for each Service.

func WithEnvSelectors added in v0.2.0

func WithEnvSelectors(selectors ...string) options.Option[Config]

WithEnvSelectors picks the overlay from the consumer's own env vars: the first non-empty one among selectors, trimmed and lowercased (see viper.ResolveEnvFrom), instead of the default APP_ENV then ENVIRONMENT. It is resolved when the option is applied; none set means base.yaml alone.

func WithEnvironment

func WithEnvironment(env string) options.Option[Config]

WithEnvironment sets the environment name for overlay loading.

func WithExtraEnv added in v0.2.0

func WithExtraEnv(bindings map[string][]string) options.Option[Config]

WithExtraEnv binds config keys to env var names (key → names, first set wins), for keys outside the schema or to replace a schema key's derived binding (see viper.Config.ExtraEnv). Repeated calls merge: each adds its keys, and a later entry for the same key replaces the earlier one. The caller's map is copied.

func WithSchema added in v0.2.0

func WithSchema(root any) options.Option[Config]

WithSchema sets the consumer's root config struct (or a pointer to one) used to derive env bindings. Without a schema, UnmarshalKey sees env overrides only for keys present in the YAML or listed in WithExtraEnv.

Types

type Config

type Config struct {
	// Viper holds Viper-specific configuration.
	Viper ViperConfig

	// Kind specifies which config loader implementation to use.
	Kind Kind
}

Config is the top-level configuration for the config loader factory.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default config with KindViper and sensible defaults.

func (Config) ToOptions

func (c Config) ToOptions() []options.Option[Config]

ToOptions converts this Config to a slice of Option functions.

type Kind

type Kind int

Kind specifies which config loader implementation to use.

const (
	// KindViper uses a Viper-backed loader that reads hierarchical YAML
	// config: base.yaml -> {env}.yaml -> secrets.yaml -> env vars.
	KindViper Kind = iota
)

func (Kind) String

func (k Kind) String() string

String returns the string representation of Kind.

type ViperConfig

type ViperConfig = viperloader.Config

ViperConfig is the Viper backend's configuration: an alias of viper.Config, so every loader field (Schema, ExtraEnv, BaseDir, Env, Prefix) is settable through the factory without a hand-kept copy. See viper.Config for each field's trade-offs.

Directories

Path Synopsis
schema
infra
Package infra provides typed configuration structures for Tech AI Knowledge Engine services.
Package infra provides typed configuration structures for Tech AI Knowledge Engine services.
listquery
Package listquery is the config surface for the list-query value-suggestion facet: the row threshold above which a facet-eligible field is served from the maintained distinct_values table instead of a live DISTINCT, and the interval at which the reconcile job recomputes refcounts.
Package listquery is the config surface for the list-query value-suggestion facet: the row threshold above which a facet-eligible field is served from the maintained distinct_values table instead of a live DISTINCT, and the interval at which the reconcile job recomputes refcounts.
pipelines
Package pipelines is the config surface for the pipeline (orchestration) layer: the per-pipeline operation timeout and the multipart-upload sizing.
Package pipelines is the config surface for the pipeline (orchestration) layer: the per-pipeline operation timeout and the multipart-upload sizing.
repos
Package repos is the config surface for the repository (data-access) layer: the cache TTL/version/key-prefix and the per-operation timeout of the repository decorators.
Package repos is the config surface for the repository (data-access) layer: the cache TTL/version/key-prefix and the per-operation timeout of the repository decorators.
resilience
Package resilience is the tunable config surface for the foundation resilience decorators (retry, breaker, rate-limit, bulkhead, timeout, budget) — the per-environment knobs threaded through the repo/client/interceptor providers Each struct mirrors its primitive's tunable fields with defaults identical to the primitive's DefaultConfig(), so adopting the config surface is behavior-preserving; the providers convert these into the primitive's options.
Package resilience is the tunable config surface for the foundation resilience decorators (retry, breaker, rate-limit, bulkhead, timeout, budget) — the per-environment knobs threaded through the repo/client/interceptor providers Each struct mirrors its primitive's tunable fields with defaults identical to the primitive's DefaultConfig(), so adopting the config surface is behavior-preserving; the providers convert these into the primitive's options.
stores
Package stores is the config surface for the data (stores) layer: the page-size cap, the per-resource default page sizes and the list-query caches, so a deployer can tune pagination without a rebuild.
Package stores is the config surface for the data (stores) layer: the page-size cap, the per-resource default page sizes and the list-query caches, so a deployer can tune pagination without a rebuild.
transport
Package transport is the config surface for the edge (transport) layer: WebSocket, gRPC, CORS and HTTP tuning plus the rate-limiter toggle.
Package transport is the config surface for the edge (transport) layer: WebSocket, gRPC, CORS and HTTP tuning plus the rate-limiter toggle.
workers
Package workers is the shared config surface for background workers: the common tunables (name, telemetry, relay and sweep cadences, batching) plus the sweep-timing cross-field invariant, so every worker inherits the typed-field + Validate shape.
Package workers is the shared config surface for background workers: the common tunables (name, telemetry, relay and sweep cadences, batching) plus the sweep-timing cross-field invariant, so every worker inherits the typed-field + Validate shape.
workflows
Package workflows is the config surface for the workflow (orchestration) layer: the per-workflow operation timeout applied through workflow.Builder.WithTimeout.
Package workflows is the config surface for the workflow (orchestration) layer: the per-workflow operation timeout applied through workflow.Builder.WithTimeout.
Package viper provides a Viper-backed ConfigLoader implementation.
Package viper provides a Viper-backed ConfigLoader implementation.

Jump to

Keyboard shortcuts

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