Skip to content

Commit b7df200

Browse files
committed
Update README
1 parent 250e84c commit b7df200

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

README.md

+23-14
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,35 @@ contacts:
5959
configor.Load(&Config, "application.yml", "database.json")
6060
```
6161

62-
* Different configuration for each environment
62+
* Load configuration by environment
6363

64-
Use `CONFIGOR_ENV` to set the environment.
65-
66-
If `CONFIGOR_ENV` not set, when running tests with `go test`, the ENV will be `test`, otherwise, it will be `development`
64+
Use `CONFIGOR_ENV` to set environment, if `CONFIGOR_ENV` not set, environment will be `development` by default, and it will be `test` when running tests with `go test`
6765

6866
```go
6967
// config.go
7068
configor.Load(&Config, "config.json")
7169

7270
$ go run config.go
73-
// Will load `config.json`, `config.development.json` if it is exist
74-
// And `config.development.json` will overwrite `config.json`'s configuration
71+
// Will load `config.json`, `config.development.json` if it exists
72+
// `config.development.json` will overwrite `config.json`'s configuration
7573
// You could use this to share same configuration across different environments
7674

7775
$ CONFIGOR_ENV=production go run config.go
78-
// Will load `config.json`, `config.production.json` if it is exist
79-
// And `config.production.json` will overwrite `config.json`'s configuration
76+
// Will load `config.json`, `config.production.json` if it exists
77+
// `config.production.json` will overwrite `config.json`'s configuration
8078

8179
$ go test
82-
// Will load `config.json`, `config.test.json` if it is exist
83-
// And `config.test.json` will overwrite `config.json`'s configuration
80+
// Will load `config.json`, `config.test.json` if it exists
81+
// `config.test.json` will overwrite `config.json`'s configuration
8482

8583
$ CONFIGOR_ENV=production go test
86-
// Will load `config.json`, `config.production.json` if it is exist
87-
// And `config.production.json` will overwrite `config.json`'s configuration
84+
// Will load `config.json`, `config.production.json` if it exists
85+
// `config.production.json` will overwrite `config.json`'s configuration
86+
```
87+
88+
```go
89+
// Set environment by config
90+
configor.New(&configor.Config{Environment: "production"}).Load(&Config, "config.json")
8891
```
8992

9093
* Example Configuration
@@ -97,13 +100,19 @@ $ go run config.go
97100
// Will load `config.example.yml` automatically if `config.yml` not found and print warning message
98101
```
99102

100-
* Read From Shell Environment
103+
* Load From Shell Environment
101104

102105
```go
103106
$ CONFIGOR_APPNAME="hello world" CONFIGOR_DB_NAME="hello world" go run config.go
104-
// Will use shell environment's value if found with upcase of prefix (by default is CONFIGOR) + field name as key
107+
// Load configuration from shell environment, it's name is {{prefix}}_FieldName
108+
```
109+
110+
```go
105111
// You could overwrite the prefix with environment CONFIGOR_ENV_PREFIX, for example:
106112
$ CONFIGOR_ENV_PREFIX="WEB" WEB_APPNAME="hello world" WEB_DB_NAME="hello world" go run config.go
113+
114+
// Set prefix by config
115+
configor.New(&configor.Config{ENVPrefix: "WEB"}).Load(&Config, "config.json")
107116
```
108117

109118
* Anonymous Struct

0 commit comments

Comments
 (0)