Documentation
¶
Overview ¶
Package config is the module root for go-config (import path github.com/eslider/go-config). Use the subpackages env, yaml, json, toml, and ini for format-specific codecs and the cmd/envc command for CLI conversion.
Hero workflow (YAML + layered dotenv + process env):
yamlCfg := yaml.New(yaml.WithURL("https://example.com/config.yaml"))
envCfg := env.New(
env.WithFile(".default.env"),
env.WithFile(".env"),
env.WithCurrentEnvironment(),
)
var svc MyService
_ = yamlCfg.Unmarshal(&svc)
_ = envCfg.Unmarshal(&svc)
Example (Hero_offline) ¶
package main
import (
"fmt"
"github.com/eslider/go-config/env"
"github.com/eslider/go-config/yaml"
)
func main() {
// README hero pattern using offline sources (no network, no .env files).
y := yaml.New(yaml.WithBytes([]byte(`service: { name: demo }`)))
e := env.New(env.WithBytes([]byte("SERVICE_PORT=8080")))
var m map[string]any
_ = y.Unmarshal(&m)
var flat map[string]any
_ = e.Unmarshal(&flat)
fmt.Println(m["service"].(map[string]any)["name"], flat["service"].(map[string]any)["port"])
}
Output: demo 8080
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
envc
command
Command envc converts, queries, and merges configuration between env, YAML, JSON, TOML, and INI formats.
|
Command envc converts, queries, and merges configuration between env, YAML, JSON, TOML, and INI formats. |
|
Package env loads dotenv files and process environment variables into nested maps and Go structs.
|
Package env loads dotenv files and process environment variables into nested maps and Go structs. |
|
Package ini loads INI configuration from bytes, files, or URLs into maps and structs.
|
Package ini loads INI configuration from bytes, files, or URLs into maps and structs. |
|
internal
|
|
|
bytesutil
Package bytesutil reads entire sources into memory.
|
Package bytesutil reads entire sources into memory. |
|
keymap
Package keymap normalizes map keys recursively for cross-format matching.
|
Package keymap normalizes map keys recursively for cross-format matching. |
|
merge
Package merge provides deep map merging with configurable slice behaviour.
|
Package merge provides deep map merging with configurable slice behaviour. |
|
source
Package source provides pluggable configuration inputs (bytes, files, URLs).
|
Package source provides pluggable configuration inputs (bytes, files, URLs). |
|
structconv
Package structconv wraps mapstructure for map<->struct conversion.
|
Package structconv wraps mapstructure for map<->struct conversion. |
|
testfixtures
Package testfixtures resolves paths to files under the module's fixtures/ directory.
|
Package testfixtures resolves paths to files under the module's fixtures/ directory. |
|
Package json loads JSON configuration from bytes, files, or URLs into maps and structs, with optional key normalization and multi-source merging.
|
Package json loads JSON configuration from bytes, files, or URLs into maps and structs, with optional key normalization and multi-source merging. |
|
Package toml loads and writes TOML configuration using the shared codec pattern (sources, deep merge, key normalization, struct decode via mapstructure).
|
Package toml loads and writes TOML configuration using the shared codec pattern (sources, deep merge, key normalization, struct decode via mapstructure). |
|
Package yaml loads YAML configuration from bytes, files, or URLs into maps and structs, with optional key normalization and multi-source merging.
|
Package yaml loads YAML configuration from bytes, files, or URLs into maps and structs, with optional key normalization and multi-source merging. |
Click to show internal directories.
Click to hide internal directories.