1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-17 17:44:30 +02:00
go-micro/config/source/flag/README.md

48 lines
758 B
Markdown
Raw Normal View History

2019-05-31 00:11:13 +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
2022-09-30 20:32:55 +02:00
```go
2019-05-31 00:11:13 +02:00
dbAddress := flag.String("database_address", "127.0.0.1", "the db address")
dbPort := flag.Int("database_port", 3306, "the db port)
```
Becomes
```json
{
2022-09-30 20:32:55 +02:00
"database": {
"address": "127.0.0.1",
"port": 3306
}
2019-05-31 00:11:13 +02:00
}
```
## New Source
```go
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
```go
// Create new config
conf := config.NewConfig()
2019-09-04 09:49:58 +02:00
// Load flag source
2019-05-31 00:11:13 +02:00
conf.Load(flagSource)
```