Update README.md
This commit is contained in:
parent
3cfca330c1
commit
0b38a26cf2
39
README.md
39
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** |
|
| 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** |
|
| 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** |
|
| 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
|
#### 1. Data types
|
||||||
@ -35,7 +36,7 @@ Like JSON, Yaml, **config** uses tags to define configurations:
|
|||||||
* slice type. e.g: []string, []int ...
|
* slice type. e.g: []string, []int ...
|
||||||
|
|
||||||
#### 2. Defines **default** values
|
#### 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
|
```golang
|
||||||
type Log struct {
|
type Log struct {
|
||||||
Path string `default:"/var/logs"`
|
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
|
#### 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
|
```golang
|
||||||
type Database struct {
|
type Database struct {
|
||||||
Host string `json:"host"`
|
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
|
#### 4. Defines configuration name for Yaml
|
||||||
Like parsing Yaml object, using **yaml** keyword to define configuration name
|
Like parsing Yaml object, using **yaml** keyword to define configuration name
|
||||||
```golang
|
```golang
|
||||||
@ -72,6 +87,16 @@ Like parsing Yaml object, using **yaml** keyword to define configuration name
|
|||||||
Log Log `yaml:"log"`
|
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
|
#### 5. Defines configuration name for Environment variable
|
||||||
Using **env** keyword to define configuration name
|
Using **env** keyword to define configuration name
|
||||||
@ -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
|
#### 6. Defines configuration name for Command line
|
||||||
Using **cli** keyword to define configuration name
|
Using **cli** keyword to define configuration name
|
||||||
```golang
|
```golang
|
||||||
|
Loading…
Reference in New Issue
Block a user