From 69dbb09aa26629c8cd1084a72d20f55231485f0e Mon Sep 17 00:00:00 2001 From: eschao Date: Tue, 12 Dec 2017 22:51:25 +0800 Subject: [PATCH 01/12] Update README.md --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74e2089..ce1bbf0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# Config -A golang library for configuration +## Introduction +**config** is a simple golang library and designed to read configurations from JSON, Yaml files, environment variables and command line. **config** depends on [go-yaml](https://github.com/go-yaml/yaml) to anlayze Yaml file and use built-in JSON library to handle JSON file. + +## Installation +1. Install [Yaml](https://github.com/go-yaml/yaml) library first: +``` +go get gopkg.in/yaml.v2 +``` + +2. Run the below to install: +``` +go get github.com/eschao/config +``` + +## Usage From e14ed1d5bc31ae632e593d8d99ab20a519279aa0 Mon Sep 17 00:00:00 2001 From: eschao Date: Tue, 12 Dec 2017 23:18:55 +0800 Subject: [PATCH 02/12] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce1bbf0..4486178 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Introduction -**config** is a simple golang library and designed to read configurations from JSON, Yaml files, environment variables and command line. **config** depends on [go-yaml](https://github.com/go-yaml/yaml) to anlayze Yaml file and use built-in JSON library to handle JSON file. +**config** is a simple golang library and designed to read configurations from JSON, Yaml files, environment variables and command line. **config** depends on [go-yaml](https://github.com/go-yaml/yaml) to anlayze Yaml file and use built-in golang library to handle JSON file. ## Installation 1. Install [Yaml](https://github.com/go-yaml/yaml) library first: @@ -7,9 +7,23 @@ go get gopkg.in/yaml.v2 ``` -2. Run the below to install: +2. Install **config** library: ``` go get github.com/eschao/config ``` ## Usage +#### Defines **default** values +**config** library supports defining a default value for structure members by using **default** keyword in structure tags +```golang + type Database struct { + Username string `default:"admin"` + Password string `default:"admin"` + } +``` + +After specified default value in tags, calls ```config.ParseDefault(interface{})``` to set it on structure instance, example codes as the below: +```golang + dbConfig := Database{} + config.ParseDefault(&dbConfig) +``` From 8f8a3d74641fa11374940d140b42a44bd83d9173 Mon Sep 17 00:00:00 2001 From: eschao Date: Tue, 12 Dec 2017 23:33:47 +0800 Subject: [PATCH 03/12] Update README.md --- README.md | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4486178..dd2d242 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Introduction -**config** is a simple golang library and designed to read configurations from JSON, Yaml files, environment variables and command line. **config** depends on [go-yaml](https://github.com/go-yaml/yaml) to anlayze Yaml file and use built-in golang library to handle JSON file. +**config** is a simple golang library and designed to read configurations from JSON, Yaml files, environment variables and command line. **config** depends on [go-yaml](https://github.com/go-yaml/yaml) to anlayze Yaml file and uses built-in golang library to handle JSON file. ## Installation 1. Install [Yaml](https://github.com/go-yaml/yaml) library first: @@ -13,17 +13,35 @@ go get github.com/eschao/config ``` ## Usage -#### Defines **default** values +#### 1. Defines **default** values **config** library supports defining a default value for structure members by using **default** keyword in structure tags ```golang - type Database struct { - Username string `default:"admin"` - Password string `default:"admin"` + type Log struct { + Path string `default:"/var/logs"` + Level string `default:"debug"` } ``` -After specified default value in tags, calls ```config.ParseDefault(interface{})``` to set it on structure instance, example codes as the below: +After that, calls ```config.ParseDefault(interface{})``` to set it on structure instance, example codes as the below: +```golang + logConfig := Log{} + config.ParseDefault(&logConfig) +``` + +#### 2. Reads configurations from JSON file +Like analyzing JSON object from file, reading configurations from JSON file is also simple: +```golang + type Database struct { + Host string `json:"host"` + Port int `json:"port"` + Username string `json:"username" default:"admin"` + Password string `json:"password" default:"admin"` + Log Log `json:"log"` + } +``` + +Parsing configurations from JSON: ```golang dbConfig := Database{} - config.ParseDefault(&dbConfig) + config.ParseConfigFile(&dbConfig, "config.json") ``` From a8da608a368845b7fd8b74fb98e371c2c6f091c9 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 00:27:48 +0800 Subject: [PATCH 04/12] Update README.md --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd2d242..31508bb 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,17 @@ go get github.com/eschao/config ``` ## Usage -#### 1. Defines **default** values -**config** library supports defining a default value for structure members by using **default** keyword in structure tags +#### I. Data types +Like JSON, Yaml, **config** uses tags to define configurations. It supports the following golang data types: + * bool + * string + * int8, int16, int, int32, int64 + * uint8, uint16, uint, uint32, uint64 + * float32, float64 + * slice type. e.g: []string, []int ... + +#### II. Defines **default** values +Using **default** keyword in structure tags to define default value. Example codes: ```golang type Log struct { Path string `default:"/var/logs"` @@ -22,14 +31,14 @@ go get github.com/eschao/config } ``` -After that, calls ```config.ParseDefault(interface{})``` to set it on structure instance, example codes as the below: +After that, calls ```config.ParseDefault(interface{})``` to set structure instance with default values. Example codes: ```golang logConfig := Log{} config.ParseDefault(&logConfig) ``` -#### 2. Reads configurations from JSON file -Like analyzing JSON object from file, reading configurations from JSON file is also simple: +#### III. Reads configurations from JSON and Yaml files +##### 1. Using ```json``` to define configuration name ```golang type Database struct { Host string `json:"host"` @@ -40,6 +49,17 @@ Like analyzing JSON object from file, reading configurations from JSON file is a } ``` +##### 2. Using ```yaml``` to define configuration name +```golang + type Database struct { + Host string `yaml:"host"` + Port int `yaml:"port"` + Username string `yaml:"username" default:"admin"` + Password string `yaml:"password" default:"admin"` + Log Log `yaml:"log"` + } +``` + Parsing configurations from JSON: ```golang dbConfig := Database{} From 3cfca330c1204e54ba4e2269185b2d1dfdcf3a9e Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 09:33:21 +0800 Subject: [PATCH 05/12] Update README.md --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 31508bb..760013e 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,20 @@ go get github.com/eschao/config ``` ## Usage -#### I. Data types -Like JSON, Yaml, **config** uses tags to define configurations. It supports the following golang data types: +### I. Define configuration name in structure tags +Like JSON, Yaml, **config** uses tags to define configurations: + +| Tag | Example | Function | +|-----|---------|------| +| json | Host string `json:"host"` | Maps `Host` to a JSON field: **host** | +| yaml | Host string `yaml:"host"` | Maps `Host` to a Yaml field: **host** | +| env | Host string `env:"HOST"` | Maps `Host` to a Environment variable: **HOST** | +| cli | Host string `cli:"host database host"` | Maps `Host` to a command line argument: **-host** or **--host** | +| default | Port int `default:"8080"` | Defines the port with default value: **8080** | + + +#### 1. Data types + **config** supports the following golang data types: * bool * string * int8, int16, int, int32, int64 @@ -22,7 +34,7 @@ Like JSON, Yaml, **config** uses tags to define configurations. It supports the * float32, float64 * slice type. e.g: []string, []int ... -#### II. Defines **default** values +#### 2. Defines **default** values Using **default** keyword in structure tags to define default value. Example codes: ```golang type Log struct { @@ -37,8 +49,8 @@ After that, calls ```config.ParseDefault(interface{})``` to set structure instan config.ParseDefault(&logConfig) ``` -#### III. Reads configurations from JSON and Yaml files -##### 1. Using ```json``` to define configuration name +#### 3. Defines configruation name for JSON +Like parsing JSON object, using **json** keyword to define configuration name ```golang type Database struct { Host string `json:"host"` @@ -49,6 +61,46 @@ After that, calls ```config.ParseDefault(interface{})``` to set structure instan } ``` +#### 4. Defines configuration name for Yaml +Like parsing Yaml object, using **yaml** keyword to define configuration name +```golang + type Database struct { + Host string `yaml:"host"` + Port int `yaml:"port"` + Username string `yaml:"username" default:"admin"` + Password string `yaml:"password" default:"admin"` + Log Log `yaml:"log"` + } +``` + +#### 5. Defines configuration name for Environment variable +Using **env** keyword to define configuration name +```golang + type Database struct { + Host string `env:"DB_HOST"` + Port int `env:"DB_PORT"` + Username string `env:"DB_USER" default:"admin"` + Password string `env:"DB_PASSWORD" default:"admin"` + Log Log `env:"DB_LOG_"` + } +``` + +#### 6. Defines configuration name for Command line +Using **cli** keyword to define configuration name +```golang + type Database struct { + Host string `cli:"host database host name"` + Port int `cli:"port database port"` + Username string `cli:"username database username" default:"admin"` + Password string `cli:"password database password" default:"admin"` + Log Log `cli:"log database log configurations"` + } +``` + +#### III. Reads configurations from JSON and Yaml files +##### 1. Using ```json``` to define configuration name + + ##### 2. Using ```yaml``` to define configuration name ```golang type Database struct { From 0b38a26cf235fd1c3847c025fba6d0a4a218b0f1 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 09:52:27 +0800 Subject: [PATCH 06/12] Update README.md --- README.md | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 760013e..7752fed 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Like JSON, Yaml, **config** uses tags to define configurations: | env | Host string `env:"HOST"` | Maps `Host` to a Environment variable: **HOST** | | cli | Host string `cli:"host database host"` | Maps `Host` to a command line argument: **-host** or **--host** | | default | Port int `default:"8080"` | Defines the port with default value: **8080** | +| separator | Path string `json:"path" separator:";"` | Separator is used to split string to a slice | #### 1. Data types @@ -35,7 +36,7 @@ Like JSON, Yaml, **config** uses tags to define configurations: * slice type. e.g: []string, []int ... #### 2. Defines **default** values -Using **default** keyword in structure tags to define default value. Example codes: +Using **default** keyword in structure tags to define default value: ```golang type Log struct { Path string `default:"/var/logs"` @@ -50,7 +51,7 @@ After that, calls ```config.ParseDefault(interface{})``` to set structure instan ``` #### 3. Defines configruation name for JSON -Like parsing JSON object, using **json** keyword to define configuration name +Like parsing JSON object, using **json** keyword to define configuration name: ```golang type Database struct { Host string `json:"host"` @@ -61,6 +62,20 @@ Like parsing JSON object, using **json** keyword to define configuration name } ``` +Corresponding JSON file: +```json + { + "host": "test.db.hostname" + "port": 8080 + "username": "amdin" + "password": "admin" + "log": { + "path": "/var/logs/db" + "level": "debug" + } + } + ``` + #### 4. Defines configuration name for Yaml Like parsing Yaml object, using **yaml** keyword to define configuration name ```golang @@ -72,7 +87,17 @@ Like parsing Yaml object, using **yaml** keyword to define configuration name Log Log `yaml:"log"` } ``` - +Corresponding Yaml file: +```yaml + host: test.db.hostname + port: 8080 + username: amdin + password: admin + log: + path: /var/logs/db + level: debug + ``` + #### 5. Defines configuration name for Environment variable Using **env** keyword to define configuration name ```golang @@ -85,6 +110,16 @@ Using **env** keyword to define configuration name } ``` +Corresponding Environment variables: +```shell + export DB_HOST=test.db.hostname + export DB_PORT=8080 + export DB_USER=admin + export DB_PASSWORD=admin + export DB_LOG_PATH=/var/logs/db + export DB_LOG_LEVEL=debug +``` + #### 6. Defines configuration name for Command line Using **cli** keyword to define configuration name ```golang From 97ad5096d311604103d68951e3f92753c79f0ce0 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 10:19:42 +0800 Subject: [PATCH 07/12] Update README.md --- README.md | 58 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7752fed..286d4a3 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,6 @@ Using **default** keyword in structure tags to define default value: } ``` -After that, calls ```config.ParseDefault(interface{})``` to set structure instance with default values. Example codes: -```golang - logConfig := Log{} - config.ParseDefault(&logConfig) -``` - #### 3. Defines configruation name for JSON Like parsing JSON object, using **json** keyword to define configuration name: ```golang @@ -65,12 +59,12 @@ Like parsing JSON object, using **json** keyword to define configuration name: Corresponding JSON file: ```json { - "host": "test.db.hostname" - "port": 8080 - "username": "amdin" + "host": "test.db.hostname", + "port": 8080, + "username": "amdin", "password": "admin" "log": { - "path": "/var/logs/db" + "path": "/var/logs/db", "level": "debug" } } @@ -119,6 +113,7 @@ Corresponding Environment variables: export DB_LOG_PATH=/var/logs/db export DB_LOG_LEVEL=debug ``` +Since the ```Log``` is a structure and nested in ```Database``` structure, the tag of ```Log``` and tags of its structure members will be combined to be an unique environment variable, for example: ```Path``` will be mapped to environment var: ```DB_LOG_PATH```. But if the ```Log``` has no tag defination, only tags of its structure members will be used, that means the ```Path``` will be mapped to ```PATH```. #### 6. Defines configuration name for Command line Using **cli** keyword to define configuration name @@ -132,21 +127,44 @@ Using **cli** keyword to define configuration name } ``` -#### III. Reads configurations from JSON and Yaml files -##### 1. Using ```json``` to define configuration name +Corresponding command line: +```shell + ./main -host test.db.hostname -port 8080 -username admin -password admin log -path /var/logs/db -level debug +``` +or +```shell + ./main -host=test.db.hostname -port=8080 -username=admin -password=admin log -path=/var/logs/db -level=debug +``` - -##### 2. Using ```yaml``` to define configuration name +#### 7. Defines configuration name as a slice type +Using **separator** to split string as a slice: ```golang - type Database struct { - Host string `yaml:"host"` - Port int `yaml:"port"` - Username string `yaml:"username" default:"admin"` - Password string `yaml:"password" default:"admin"` - Log Log `yaml:"log"` + type Log struct { + Levels []string `env:"LEVELS" cli:"levels log levels" separator:";"` } ``` +If the separator is not given, its default is **:**, The separator only works on **env** and **cli** tags +```golang + logConfig := Log{} + // export LEVELS=debug;error;info + config.ParseEnv(&logConfig) + // logConfig[0] == debug + // logConfig[1] == error + // logConfig[2] == info +``` + +### II. Parses configurations +#### 1. Parses default values +When default values are defined in tags, calls ```config.ParseDefault(interface{})``` to assign them to given structure instance **BEFORE** parsing any other configuration types: +```golang + logConfig := Log{} + config.ParseDefault(&logConfig) +``` +>Note: Other parsing functions won't set structure instance with default values whatever if the configuration is provided or not + +#### 2. Parses configuration files: + Parsing configurations from JSON: ```golang dbConfig := Database{} From cd1d79b9bcef92dfef6d2b7d9c7f398a420c9ec7 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 10:39:18 +0800 Subject: [PATCH 08/12] Update README.md --- README.md | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 286d4a3..bdadd57 100644 --- a/README.md +++ b/README.md @@ -161,12 +161,46 @@ When default values are defined in tags, calls ```config.ParseDefault(interface{ logConfig := Log{} config.ParseDefault(&logConfig) ``` ->Note: Other parsing functions won't set structure instance with default values whatever if the configuration is provided or not +>Note: Other parsing functions won't set structure instance with default values whatever if the configuration value is provided or not -#### 2. Parses configuration files: +#### 2. Parses from Environment variables +```golang + dbConfig := Database{} + config.ParseEnv(&dbConfig) +``` -Parsing configurations from JSON: +#### 3. Parses from Command line +```golang + dbConfig := Database{} + config.ParseCli(&dbConfig) +``` + +#### 4. Parses from default configuration files +Calls **ParseConfigFile(interface{}, string)** to parse given configuration file: ```golang dbConfig := Database{} config.ParseConfigFile(&dbConfig, "config.json") ``` + +If the configuration file is not given, the default configuration files: **config.json** and **config.yaml** will be located under the same folder with fixed searching order. + +The **config.json** will be always first located, if it doesn't exist, then checks **config.yaml**. If all of them are not found, parsing will fail. +```golang + dbConfig := Database{} + config.ParseConfigFile(&dbConfig, "") +``` + +#### 4. Parses from configuration file specified by command line +Calls **ParseConfig(interface{}, string)** to parse the configuration file given by command line. The second parameter is a command line argument which is used to specifiy config file: +```golang + dbConfig := Database{} + config.ParseConfig(&dbConfig, "c") +``` +Run application like: +```shell + ./main -c config.json +``` +**ParseConfig()** will analyze command line argument and extract **config.json** from argument **-c** + + + From bc224778bfd160ead2e584aaceba7ecb33039c31 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 11:01:34 +0800 Subject: [PATCH 09/12] Update README.md --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bdadd57..b96d24f 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Corresponding JSON file: "host": "test.db.hostname", "port": 8080, "username": "amdin", - "password": "admin" + "password": "admin", "log": { "path": "/var/logs/db", "level": "debug" @@ -126,6 +126,7 @@ Using **cli** keyword to define configuration name Log Log `cli:"log database log configurations"` } ``` +For **cli** definition, the string before the first space is command line argument, the rest string are the command line usage and will be oupputed when printing usage Corresponding command line: ```shell @@ -202,5 +203,51 @@ Run application like: ``` **ParseConfig()** will analyze command line argument and extract **config.json** from argument **-c** +### III. Multi-configurations +You can define all supported configuration tags in a structure and call corresponding functions in your desired order to parse. +Examples: +```golang + type Log struct { + Path string `json:"path" yaml:"path" env:"PATH" cli:"path log path" default:"/var/logs"` + Levels string `json:"levels" yaml:"levels" env:"LEVELS" cli:"levels log levels" default:"debug;error"` + } + + type Database struct { + Host string `json:"host" yaml:"host" env:"DB_HOST" cli:"host database host name"` + Port int `json:"port" yaml:"port" env:"DB_PORT" cli:"port database port"` + Username string `json:"user" yaml" user" env:"DB_USER" cli:"username database username" default:"admin"` + Password string `json:"passwd" yaml:"passwd" env:"DB_PASSWD" cli:"password database password" default:"admin"` + Log Log `json:"log" yaml:"log" env:"DB_LOG_" cli:"log database log configurations"` + } +``` +Then, you can parse them like below: +```golang + dbConfig := Database{} + + // parse default values + if err := config.ParseDefault(&dbConfig); err != nil { + // error handling + } + + // parse configuration file from command line + err := config.ParseConfig(&dbConfig, "c") + + // parse default configurations + if err != nil { + err = config.ParseConfigFile(&dbConfig), "") + } + + // parse environment variables + if err != nil { + err = config.ParseEnv(&dbConfig) + } + + // parse command line + if err != nil { + err = config.ParseCli(&dbConfig) + } +``` + +You don't need call all of them. Invokes parsing function that your need. From 64108c1977933951b274bdf69d379200dede56ce Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 11:07:24 +0800 Subject: [PATCH 10/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b96d24f..8f0c44e 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Corresponding Environment variables: export DB_LOG_PATH=/var/logs/db export DB_LOG_LEVEL=debug ``` -Since the ```Log``` is a structure and nested in ```Database``` structure, the tag of ```Log``` and tags of its structure members will be combined to be an unique environment variable, for example: ```Path``` will be mapped to environment var: ```DB_LOG_PATH```. But if the ```Log``` has no tag defination, only tags of its structure members will be used, that means the ```Path``` will be mapped to ```PATH```. +Since the ```Log``` is a structure and nested in ```Database``` structure, the tag of ```Log``` and tags of its structure members will be combined to be an unique environment variable, for example: ```Path``` will be mapped to environment var: ```DB_LOG_PATH```. But if the ```Log``` has no tag definition, only tags of its structure members will be used, that means the ```Path``` will be mapped to ```PATH```. #### 6. Defines configuration name for Command line Using **cli** keyword to define configuration name From 0e5b87611715aaef4bc64c08204387e515520559 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 11:09:01 +0800 Subject: [PATCH 11/12] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f0c44e..098a07c 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ Examples: Log Log `json:"log" yaml:"log" env:"DB_LOG_" cli:"log database log configurations"` } ``` -Then, you can parse them like below: +Then, you can parse as below: ```golang dbConfig := Database{} @@ -251,3 +251,6 @@ Then, you can parse them like below: You don't need call all of them. Invokes parsing function that your need. +## License +This project is licensed under the Apache License Version 2.0. + From b7b77cb26eb22f2ec17e9087cf5de686033ce886 Mon Sep 17 00:00:00 2001 From: eschao Date: Wed, 13 Dec 2017 11:12:11 +0800 Subject: [PATCH 12/12] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 098a07c..598a0bd 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ Calls **ParseConfigFile(interface{}, string)** to parse given configuration file If the configuration file is not given, the default configuration files: **config.json** and **config.yaml** will be located under the same folder with fixed searching order. -The **config.json** will be always first located, if it doesn't exist, then checks **config.yaml**. If all of them are not found, parsing will fail. +The **config.json** will always be located first, if it doesn't exist, then checks **config.yaml**. If all of them are not found, parsing will fail. ```golang dbConfig := Database{} config.ParseConfigFile(&dbConfig, "") @@ -203,7 +203,7 @@ Run application like: ``` **ParseConfig()** will analyze command line argument and extract **config.json** from argument **-c** -### III. Multi-configurations +### III. Multi-Configurations You can define all supported configuration tags in a structure and call corresponding functions in your desired order to parse. Examples: @@ -247,6 +247,9 @@ Then, you can parse as below: if err != nil { err = config.ParseCli(&dbConfig) } + + // check if all requried configurations are set + ... ``` You don't need call all of them. Invokes parsing function that your need.