Skip to content

Commit

Permalink
update readme for prefixed environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaslovsky committed Dec 12, 2020
1 parent 1d07558 commit ee445ab
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ if err != nil {
}
```

### Read Environment Variables with Common Prefix

Some applications are configured with environment variables that share the same prefix. Prefixed
environment variables such as `APPNAME_PORT, APPNAME_HOST, ...` can be read without repeating the
prefix in struct tags:
```go
import github.com/ilyakaznacheev/cleanenv

type ConfigDatabase struct {
Port string `env:"PORT" env-default:"5432"`
Host string `env:"HOST" env-default:"localhost"`
Name string `env:"NAME" env-default:"postgres"`
User string `env:"USER" env-default:"user"`
Password string `env:"PASSWORD"`
}

var cfg ConfigDatabase

err := cleanenv.ReadEnvWithPrefix("appname", &cfg)
if err != nil {
...
}
```

### Update Environment Variables

Some environment variables may change during the application run. To get the new values you need to mark these variables as updatable with the tag `env-upd` and then run the update function:
Expand Down

0 comments on commit ee445ab

Please sign in to comment.