-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c394a77
commit 53da350
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |