Skip to content

Commit

Permalink
Add docs for LoadConfigFileWithPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
pavleprica committed Dec 20, 2022
1 parent 911cf50 commit 374052e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ _In this example, the `${}` template values will be loaded from system environme

#### Using the loader

`cfgm.LoadConfigFile()`

To use the loader, just invoke `cfgm.LoadConfigFile("local")` or in dev case `cfgm.LoadConfigFile("dev")`.
It in turn will return the `cfgm.Manager` [type](cfgm/manager.go). Which offers functions to get values.
In a bigger context an example would be:
Expand Down Expand Up @@ -212,4 +214,38 @@ func main() {
}
```

`cfgm.LoadConfigFileWithPath()`

This loader is doing the same job as `cfgm.LoadConfigFile()` but it doesn't look via the `environment` variable, rather just takes
the custom path provided.
It in turn will return the `cfgm.Manager` [type](cfgm/manager.go). Which offers functions to get values.
In a bigger context an example would be:

```go
func main() {
manager, err := cfgm.LoadConfigFileWithPath("/Users/someuser/yourproject/config.yaml")
if err != nil {
log.Fatal(err)
}
e := echo.New()
// Single value
loggerEnabled, err := manager.Get("server.logging")
if err != nil {
log.Fatal(err)
}
if loggerEnabled == "enabled" {
log.Println("Using logger")
e.Use(middleware.Logger())
}
e.Use(middleware.Recover())
manager.GetOrDefault("port", "9000")
e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", manager.GetOrDefault("port", "9000"))))
}
```

Example project code can be found [here](https://github.com/go-nag/configuration-example).

0 comments on commit 374052e

Please sign in to comment.