micro/config/source/flag
Vasiliy Tolstov 199ff66bd4
enable cache for build, closes #8 (#12)
* enable cache for build, closes #8
* goimports
* lint fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-08-20 15:23:41 +03:00
..
flag_test.go Add 1.13 support. Fix tests to enable 1.13 support 2019-09-27 17:14:24 +01:00
flag.go enable cache for build, closes #8 (#12) 2020-08-20 15:23:41 +03:00
options.go regen files with never protoc (#6) 2020-08-19 17:47:17 +03:00
README.md Update config source README file 2019-09-04 15:49:58 +08:00

Flag Source

The flag source reads config from flags

Format

We expect the use of the flag package. Upper case flags will be lower cased. Dashes will be used as delimiters.

Example

dbAddress := flag.String("database_address", "127.0.0.1", "the db address")
dbPort := flag.Int("database_port", 3306, "the db port)

Becomes

{
    "database": {
        "address": "127.0.0.1",
        "port": 3306
    }
}

New Source

flagSource := flag.NewSource(
	// optionally enable reading of unset flags and their default
	// values into config, defaults to false
	IncludeUnset(true)
)

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load flag source
conf.Load(flagSource)