Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wgarunap/goconf
Load environmental variable values to go struct directly
https://github.com/wgarunap/goconf
config configuration configuration-management env environment-variables golang golang-library tryfix
Last synced: 3 months ago
JSON representation
Load environmental variable values to go struct directly
- Host: GitHub
- URL: https://github.com/wgarunap/goconf
- Owner: wgarunap
- License: mit
- Created: 2020-02-06T05:01:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-04T19:06:26.000Z (over 1 year ago)
- Last Synced: 2023-10-05T06:40:07.698Z (over 1 year ago)
- Topics: config, configuration, configuration-management, env, environment-variables, golang, golang-library, tryfix
- Language: Go
- Homepage: http://tryfix.io
- Size: 17.6 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Config
Library to load env configuration### How to use it
```go
package main
import ("errors"
"github.com/caarlos0/env/v6"
"github.com/wgarunap/goconf"
"log"
)type Conf struct {
Name string `env:"MY_NAME"`
}var Config Conf
func (Conf) Register()error {
return env.Parse(&Config)
}func (Conf) Validate() error{
if Config.Name == "" {
return errors.New(`MY_NAME environmental variable cannot be empty`)
}
return nil
}func (Conf) Print() interface{} {
return Config
}func main() {
err := goconf.Load(
new(Conf),
)
if err != nil{
log.Fatal(err)
}
log.Print(`configuration loaded, `,Config.Name)
}```