Skip to content

Instantly share code, notes, and snippets.


Martin Piegay cocap10

View GitHub Profile
View staertdemo.use.go
// Create staert object
// Adding sources
// Parse and merge sources
loadedConfig, err := s.LoadConfig()
View staertdemo.try.toml
# This is a TOML document.
LogLevel = "DEBUG"
Timeout = "2s"
name = "Tom Preston-Werner"
DateOfBirth = 1979-05-27T07:32:00-08:00
Rate = 0.75
View staertdemo.create.sources.go
// TOML source
toml:=staert.NewTomlSource("example", []string{"./toml/", "/any/other/path"})
// Flaeg source
f:=flaeg.New(command, os.Args[1:])
// Key-Value Store source
kv, err :=staert.NewKvSource(backend, options, “prefix”)
View flaegdemo.use.go
f := flaeg.New(flaegCmd, os.Args[1:])
if err := f.Run(); err != nil {
$ ./flaegdemo
{"VersionName":"Rebloch","LogLevel":"INFO","Timeout":1000000000,"Db":null,"Owner":{"Name":"default owner","DateOfBirth":"2016-08-03T17:36:20.85900754+02:00","Rate":0.5}}
$ ./flaegdemo --db
{"VersionName":"Rebloch","LogLevel":"INFO","Timeout":1000000000,"Db":{"ConnectionMax":100,"ConnectionMax64":6400000000000000000,"Watch":true,"IP":""},"Owner":{"Name":"default owner","DateOfBirth":"2016-08-03T17:36:33.683130019+02:00","Rate":0.5}}
$ ./flaegdemo --db.ip= --owner.dob=1979-05-27T07:32:00Z
{"VersionName":"Rebloch","LogLevel":"INFO","Timeout":1000000000,"Db":{"ConnectionMax":100,"ConnectionMax64":6400000000000000000,"Watch":true,"IP":""},"Owner":{"Name":"default owner","DateOfBirth":"1979-05-27T07:32:00Z","Rate":0.5}}
$ ./flaegdemo --help
flaegdemo is a golang program...(here the program description)
Usage: flaegdemo [--flag=flag_argument] [-f[flag_argument]] ... set flag_argument to flag(s)
or: flaegdemo [--flag[=true|false| ]] [-f[true|false| ]] ... set true/false to boolean flag(s)
Available Commands:
version Print version
Use "flaegdemo [command] --help" for more information about a command.
View flaegdemo.config.go
//Configuration is a struct which contains all differents type to field
//using parsers on string, time.Duration, pointer, bool, int, int64, time.Time, float64
type Configuration struct {
VersionName string //no description struct tag, it will not be flaged
LogLevel string `short:"l" description:"Log level"` //string type field, short flag "-l"
Timeout time.Duration `description:"Timeout duration"` //time.Duration type field
Db *DatabaseInfo `description:"Enable database"` //pointer type field (on DatabaseInfo)
Owner *OwnerInfo `description:"Enable Owner description"` //another pointer type field (on OwnerInfo)
cocap10 / flaegdemo.cmd.go
Last active Aug 4, 2016
Golang Configuration Made Easy With Flæg And Stært
View flaegdemo.cmd.go
flaegCmd := &flaeg.Command{
Name: "flaegdemo",
Description: "flaegdemo is a golang program...(here the program description)",
Config: &config,
DefaultPointersConfig: &defaultConfigOfPointerFields,
Run: func() error {
printableConfig, _ := json.Marshal(config)
fmt.Printf("%s\n", printableConfig)
return nil