1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-08 22:20:05 +00:00
cloudkeys-go/vendor/github.com/Luzifer/rconfig
Martin Thielecke 9c6e3c89a5 JS bugfixes (#18)
* fix js scoping issue

* add external libraries (they were offline too often)

* new compiled scripts and css

* new fixes in the binary

* vendor update

* change js source

* remove needless variable

* removed more needless variables
2019-01-21 15:27:20 +01:00
..
.travis.yml JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
autoenv.go JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
autoenv_test.go JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
bool_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
config.go JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
duration_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
errors_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
example_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
float_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
general_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
History.md JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
int_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
LICENSE JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
os-args_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
precedence_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
rconfig_suite_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
README.md JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
slice_test.go JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
sub-struct_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
time_test.go JS bugfixes (#18) 2019-01-21 15:27:20 +01:00
uint_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
vardefault_providers.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
vardefault_test.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00

Build Status Go Report Card 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

OR fetch a specific version:

go get -u gopkg.in/luzifer/rconfig.v2

Run tests by running:

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

Usage

A very simple usecase is to just configure a struct inside the vars section of your main.go and to parse the commandline flags from the main() function:

package main

import (
  "fmt"
  "github.com/Luzifer/rconfig"
)

var (
  cfg = struct {
    Username string `default:"unknown" flag:"user" description:"Your name"`
    Details  struct {
      Age int `default:"25" flag:"age" env:"age" description:"Your age"`
    }
  }{}
)

func main() {
  rconfig.Parse(&cfg)

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

Provide variable defaults by using a file

Given you have a file ~/.myapp.yml containing some secrets or usernames (for the example below username is assumed to be "luzifer") as a default configuration for your application you can use this source code to load the defaults from that file using the vardefault tag in your configuration struct.

The order of the directives (lower number = higher precedence):

  1. Flags provided in command line
  2. Environment variables
  3. Variable defaults (vardefault tag in the struct)
  4. default tag in the struct
var cfg = struct {
  Username string `vardefault:"username" flag:"username" description:"Your username"`
}

func main() {
  rconfig.SetVariableDefaults(rconfig.VarDefaultsFromYAMLFile("~/.myapp.yml"))
  rconfig.Parse(&cfg)

  fmt.Printf("Username = %s", cfg.Username)
  // Output: Username = luzifer
}

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.