github.com/annwntech/go-micro/v2@v2.9.5/config/source/flag/README.md (about)

     1  # Flag Source
     2  
     3  The flag source reads config from flags
     4  
     5  ## Format
     6  
     7  We expect the use of the `flag` package. Upper case flags will be lower cased. Dashes will be used as delimiters.
     8  
     9  ### Example
    10  
    11  ```
    12  dbAddress := flag.String("database_address", "127.0.0.1", "the db address")
    13  dbPort := flag.Int("database_port", 3306, "the db port)
    14  ```
    15  
    16  Becomes
    17  
    18  ```json
    19  {
    20      "database": {
    21          "address": "127.0.0.1",
    22          "port": 3306
    23      }
    24  }
    25  ```
    26  
    27  ## New Source
    28  
    29  ```go
    30  flagSource := flag.NewSource(
    31  	// optionally enable reading of unset flags and their default
    32  	// values into config, defaults to false
    33  	IncludeUnset(true)
    34  )
    35  ```
    36  
    37  ## Load Source
    38  
    39  Load the source into config
    40  
    41  ```go
    42  // Create new config
    43  conf := config.NewConfig()
    44  
    45  // Load flag source
    46  conf.Load(flagSource)
    47  ```