package config import ( "log" "os" "github.com/spf13/viper" ) type Key string const ( Environment Key = `app.environment` Port Key = `app.port` DBType Key = `db.type` DBHost Key = `db.host` DBPort Key = `db.port` DBUser Key = `db.user` DBPassword Key = `db.password` DBDatabase Key = `db.database` ) func (k Key) GetString() string { return viper.GetString(string(k)) } func InitDefault() { viper.SetDefault(string(Environment), "local") viper.SetDefault(string(Port), "8080") } func Init() { log.Print("Initialising config...") viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") err := viper.ReadInConfig() if err != nil { log.Fatal("Could not read config file: \n", err) os.Exit(1) } }