import "github.com/altessa-s/go-atlas/tools/codegen/goconfig/commands"Configuration file converter for the go-atlas config loader (config/loader).
goconfig converts between different configuration formats, understanding the config/loader environment structure with
proper field name transformations and nesting.
go install github.com/altessa-s/go-atlas/cmd/goconfig@latestgoconfig convert --from config.yaml --to .envgoconfig convert --from .env --to config.yamlgoconfig convert --from config.toml --to .env| Format | Extensions | Description |
|---|---|---|
| YAML | .yaml, .yml |
YAML configuration files |
| TOML | .toml |
TOML configuration files |
| Env | .env |
Environment variable files |
| Markdown | .md |
Documentation tables |
- camelCase → SCREAMING_SNAKE_CASE
- Nested structures use
__(double underscore) delimiter - Arrays stay in one variable as a bracketed list:
ARRAY=[a,b,c]
| YAML Structure | Environment Variable |
|---|---|
grpc.interceptors.realIP.enabled |
GRPC__INTERCEPTORS__REAL_IP__ENABLED |
database.connectionPool.maxSize |
DATABASE__CONNECTION_POOL__MAX_SIZE |
logging.outputs: [console, file] |
LOGGING__OUTPUTS=[console,file] |
Convert configuration between formats:
goconfig convert [flags]
Flags:
-f, --from string Source file or directory (required)
-t, --to string Destination file (required)
--from-format string Format of source (auto-detect by extension)
--to-format string Format of destination (auto-detect by extension)
--parse-comments Include commented lines in conversion
--use-claude Generate Markdown field descriptions with the Claude API
--claude-api-key string Claude API key (or ANTHROPIC_API_KEY)Input (config.yaml):
database:
host: localhost
port: 5432
pool:
maxSize: 10
timeout: 30s
logging:
level: info
outputs:
- console
- fileOutput (.env):
DATABASE__HOST=localhost
DATABASE__PORT=5432
DATABASE__POOL__MAX_SIZE=10
DATABASE__POOL__TIMEOUT=30s
LOGGING__LEVEL=info
LOGGING__OUTPUTS=[console,file]The real output also groups the variables by top-level section under # <Section> Configuration comment headers.
Input (.env):
SERVER__HOST=0.0.0.0
SERVER__PORT=8080
SERVER__TLS__ENABLED=true
SERVER__TLS__CERT_FILE=/etc/ssl/cert.pem
SERVER__TLS__KEY_FILE=/etc/ssl/key.pemOutput (config.yaml):
server:
host: 0.0.0.0
port: 8080
tls:
enabled: true
certFile: /etc/ssl/cert.pem
keyFile: /etc/ssl/key.pemConvert all configuration files in a directory:
# Merge configs matching the detected source format in ./configs/ into one .env
goconfig convert --from ./configs/ --to merged.env
# Convert each file individually
for f in configs/*.yaml; do
goconfig convert --from "$f" --to "env/$(basename "$f" .yaml).env"
doneThis converter produces environment variables compatible with the config/loader parser:
// Load environment variables generated by goconfig
cfg := &MyConfig{}
_, err := loader.New(&yaml3.Backend{}).Load(cfg)File format is automatically detected by extension:
.yaml,.yml→ YAML.toml→ TOML.env→ Environment variables.md→ Markdown tables
Override with --from-format and --to-format flags.
- tools/codegen/goconfig - Internal implementation
- config/loader - Configuration loading utilities
- config/templates - Commented YAML templates for every config schema