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 ¶
- func New(kind Kind, opts ...options.Option[Config]) (interfaces.ConfigLoader, error)
- func NewFromConfig(cfg Config) (interfaces.ConfigLoader, error)
- func Section[T any, PT interface{ ... }](loader interfaces.ConfigLoader, key string) (T, error)
- func WithBaseDir(dir string) options.Option[Config]
- func WithEnvPrefix(prefix string) options.Option[Config]
- func WithEnvSelectors(selectors ...string) options.Option[Config]
- func WithEnvironment(env string) options.Option[Config]
- func WithExtraEnv(bindings map[string][]string) options.Option[Config]
- func WithSchema(root any) options.Option[Config]
- type Config
- type Kind
- type ViperConfig
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 Section ¶ added in v0.0.6
func Section[T any, PT interface { *T Validate() error }](loader interfaces.ConfigLoader, key string) (T, error)
Section unmarshals the config section at key into a T and validates it, the shape of every "extract and validate a typed slice" provider in a composition root:
logging, err := config.Section[infra.LoggingConfig](loader, "logging")
T's Validate may have a value or a pointer receiver. A section that does not decode or does not validate is CodeInvalidInput, naming key; a validation error that already carries a code keeps it.
func WithBaseDir ¶
WithBaseDir sets the directory containing config files.
func WithEnvPrefix ¶
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 ¶
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 ¶
WithEnvironment sets the environment name for overlay loading.
func WithExtraEnv ¶
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.
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.
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
|
|
|
decoration
Package decoration is the config surface for every decorated component — controllers, clients, workflows, pipelines, services, repositories, stores, jobs and gates.
|
Package decoration is the config surface for every decorated component — controllers, clients, workflows, pipelines, services, repositories, stores, jobs and gates. |
|
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 multipart-upload sizing (a pipeline's timeout is a decoration layer, decoration.pipelines).
|
Package pipelines is the config surface for the pipeline (orchestration) layer: the multipart-upload sizing (a pipeline's timeout is a decoration layer, decoration.pipelines). |
|
repos
Package repos is the config surface for the repository (data-access) layer: the entity cache's TTL, version and key prefix.
|
Package repos is the config surface for the repository (data-access) layer: the entity cache's TTL, version and key prefix. |
|
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 ORM the stores are built on (Kind), 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 ORM the stores are built on (Kind), 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.
|
Package transport is the config surface for the edge (transport) layer: WebSocket, gRPC, CORS and HTTP tuning. |
|
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. |
|
Package viper provides a Viper-backed ConfigLoader implementation.
|
Package viper provides a Viper-backed ConfigLoader implementation. |