mirror of
https://github.com/SourceFellows/gobuch.git
synced 2024-10-22 22:05:35 +00:00
29 lines
511 B
Go
29 lines
511 B
Go
/*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"))
|
|
}
|