Discover Packages
github.com/adnsv/confkit
examples
02-environment
command
Version:
v0.1.2
Opens a new window with list of versions in this module.
Published: Jul 18, 2025
License: MIT
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: ? modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
Example 02: Environment Variables
Loading configuration from environment variables with prefix handling.
What This Shows
Using FromEnv to load environment variables
Prefix stripping (MYAPP_ prefix is removed during matching)
Layer precedence (environment overrides defaults)
How non-prefixed variables are ignored
Running
go run main.go
Key Points
FromEnv - Creates a layer from environment variables
Prefix Stripping - MYAPP_SERVER_PORT matches server.port
Precedence - Later layers (environment) override earlier ones (defaults)
Selective Loading - Only variables with the prefix are included
Environment Variable Matching
The library automatically matches environment variables to configuration keys:
MYAPP_SERVER_PORT → server.port
MYAPP_DATABASE_HOST → database.host
MYAPP_FEATURE_BETA → feature.beta
Output Example
=== Layer Contents ===
Layer: defaults (prefix: "")
server.port = 8080
server.host = localhost
database.host = localhost
...
Layer: environment (prefix: "MYAPP_")
MYAPP_SERVER_PORT = 9000
MYAPP_DATABASE_HOST = db.production.com
...
=== Resolved Configuration ===
server.port = 9000 (from environment)
server.host = localhost (from defaults)
database.host = db.production.com (from environment)
...
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.