Skip to content

Commit

Permalink
Add README for config package
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Dec 20, 2023
1 parent c394a77 commit 53da350
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
### Config Package

#### Overview
The `config` package manages configurations in Go applications,
ensuring compatibility between `config.yaml` and `setup.env`.
`setup.env` is used to setup environment variables.

Note - When both environment variables and config.yaml settings are present,
the package prioritizes environment variables, overriding equivalent settings in config.yaml.

#### Compatible configurations example

The below configurations are compatible in this project.

- `setup.env` contains:
```
export LOGFILE_PATH=cm-beetle.log
```
- `config.yaml` has:
```yaml
logfile:
path: ./cm-beetle.log
```
#### How to use it
- Use a blank import in your package (e.g., main, logger, and so on)
- Get a value using Viper
Note - It's just my preference. `config.Init()` can be used.
```go
import (
// other packages
// Loads configurations from setup.env and config.yaml
_ "github.com/cloud-barista/cm-beetle/pkg/config"
)
func main() {
logFilePath := viper.GetString("logfile.path")
// Application logic follows
}
```

#### Wrapping Up

This setup illustrates the package's ability to harmonize settings from both `setup.env` and `config.yaml`,
showcasing its versatility and ease of use.

0 comments on commit 53da350

Please sign in to comment.