configx-env

command
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 6 Imported by: 0

README

configx-env

Demonstrates layered file + env configuration with configx.

Run from repository root:

go run ./examples/configx-env

Expected output:

loaded config:
app.name=kernel
app.env=prod       (overridden by KERNEL_APP_ENV)
server.port=9000   (overridden by KERNEL_SERVER_PORT)
server.addr=0.0.0.0 (from base file)

The example writes a temporary JSON base file, then simulates environment overrides via KERNEL_* variables. configx.New(configx.WithSource(...)) combines them: later sources override earlier leaf values, while nested maps merge recursively.

For the full pattern (including WithResolveActualTypes, Watch, and custom decoders), see configx/example_test.go and configx/example_business_test.go.

Documentation

Overview

Package main demonstrates configx layered file + env override.

The env source produces flat key/value entries. To override a nested config path like app.env, use a placeholder in the base file that references the env-injected top-level key.

Run:

go run ./examples/configx-env

Expected output:

loaded config:
app.name=kernel
app.env=prod       (resolved from ${APP_ENV} via KERNEL_APP_ENV)
server.port=9000   (resolved from ${SERVER_PORT} via KERNEL_SERVER_PORT)
server.addr=0.0.0.0 (from base file)

Jump to

Keyboard shortcuts

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