1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/config/source/flag
2022-09-30 20:32:55 +02: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 fix: some linting issues (#2563) 2022-09-30 16:27:07 +02:00
options.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
README.md fix: linting issues (#2566) 2022-09-30 20:32:55 +02: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)