1
0
Fork 0
mirror of https://github.com/Luzifer/rconfig.git synced 2024-11-09 16:30:04 +00:00
Package rconfig implements a CLI configuration reader with struct-embedded defaults, environment variables and posix compatible flag parsing
Find a file
2015-09-08 22:07:57 +02:00
bool_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
config.go Added VarDefault functionality 2015-09-08 22:07:57 +02:00
errors_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
example_test.go Initial version of rconfig 2015-07-12 12:36:18 +02:00
float_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
general_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
int_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
LICENSE Initial version of rconfig 2015-07-12 12:36:18 +02:00
os-args_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
rconfig_suite_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
README.md Initial version of rconfig 2015-07-12 12:36:18 +02:00
slice_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
sub-struct_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
uint_test.go Moved tests to Ginkgo 2015-09-08 22:07:40 +02:00
vardefault_providers.go Added VarDefault functionality 2015-09-08 22:07:57 +02:00
vardefault_test.go Added VarDefault functionality 2015-09-08 22:07:57 +02:00

Circle CI License: Apache v2.0 Documentation

Description

Package rconfig implements a CLI configuration reader with struct-embedded defaults, environment variables and posix compatible flag parsing using the pflag library.

Installation

Install by running:

go get -u github.com/Luzifer/rconfig

Run tests by running:

go test -v -race -cover github.com/Luzifer/rconfig

Usage

As a first step define a struct holding your configuration:

type config struct {
  Username string `default:"unknown" flag:"user" description:"Your name"`
  Details  struct {
    Age int `default:"25" flag:"age" env:"age" description:"Your age"`
  }
}

Next create an instance of that struct and let rconfig fill that config:

var cfg config
func init() {
  cfg = config{}
  rconfig.Parse(&cfg)
}

You're ready to access your configuration:

func main() {
  fmt.Printf("Hello %s, happy birthday for your %dth birthday.",
		cfg.Username,
		cfg.Details.Age)
}

More info

You can see the full reference documentation of the rconfig package at godoc.org, or through go's standard documentation system by running godoc -http=:6060 and browsing to http://localhost:6060/pkg/github.com/Luzifer/rconfig after installation.