gobuch/configuration/application-configuration-viper/main.go

29 lines
511 B
Go
Raw Normal View History

2020-08-21 04:26:40 +00:00
/*Package main show how to use viper.
Start the app in the root folder with:
SERVER_HOST=testing go run cmd/main.go
*/
package main
import (
"fmt"
"strings"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()
fmt.Println(viper.Get("server.host"))
}