zcfg

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

README

zcfg

Build Status codecov

Example
type Config struct {
	API        *APIConfig        `yaml:"api"        flag:"api"`
	Clickhouse *ClickhouseConfig `yaml:"clickhouse" flag:"clickhouse"`
	Log        *LogConfig        `yaml:"log"        flag:"log"`
}

type APIConfig struct {
	Port uint16 `yaml:"port" flag:"port" env:"API_PORT"`
}

type ClickhouseConfig struct {
	Host        string        `yaml:"host"        flag:"host"        env:"CLICKHOUSE_HOST"`
	User        string        `yaml:"user"        flag:"user"        env:"CLICKHOUSE_USER"`
	Database    string        `yaml:"database"    flag:"database"    env:"CLICKHOUSE_DATABASE"`
	ReadTimeout time.Duration `yaml:"readTimeout" flag:"readTimeout" env:"CLICKHOUSE_READ_TIMEOUT"`
}

type LogConfig struct {
	Level string `yaml:"level" flag:"level" env:"LOG_LEVEL"`
}

func main() {
	var cfg Config

	cfgLoader := zcfg.New(&cfg, zcfg.FromFile("config.yaml"), zcfg.UseFlags(flag.CommandLine))
	if err := cfgLoader.Load(); err != nil {
		log.Fatal(err)
	}
}
LOG_LEVEL=DEBUG go run main.go -c config.yaml --api.port=8001 --clickhouse.user=testuser --clickhouse.database=testdb --clickhouse.readTimeout=1s
TODO
  • vault support for passwords

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFileDecoder

func RegisterFileDecoder(ext string, dec FileDecoder)

Types

type FileDecoder

type FileDecoder func(r io.Reader, dst interface{}) error

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

func New

func New(cfg interface{}, opts ...Option) *Loader

func (*Loader) Load

func (l *Loader) Load() error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func FromFile

func FromFile(path string) Option

func UseFlags

func UseFlags(flagSet *flag.FlagSet) Option

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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