Skip to content

jfk9w-go/confi

Repository files navigation

confi

Go Reference Go Report Go Coverage CodeQL

Configuration parser for Go.

Features

  • Read and merge configuration values from environment variables, stdin and files.
  • Generate JSON schema for configuration struct based on types and tags.
  • Apply default values for configuration values.
  • Support for JSON, YAML and Gob.

Usage

go get github.com/jfk9w-go/confi@latest

Command-line options

Option Description
--config.stdin=<codec> Read configuration from stdin.
Supported codecs: yaml or yml, json, gob.
--config.file=<path> Read configuration from file.
Option may be used several times in order to pass multiple files.
Codec is resolved based on filename extension. See supported codecs above.

Environment variables

Environment variables are filtered based on prefix passed to confi.Get() call.

A single configuration file may be specified via <prefix>_CONFIG_FILE environment variable.

Priority

When properties are specified in multiple ways (e.g. environment variable and CLI option), they have the following priority:

  1. CLI options.
  2. Configuration files.
  3. Environment variables.

Arrays (slices) and maps are overridden as a whole.

Example

TODO