gogmagog/config/config.go
Deepak 3a5961f003
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
adds basic db stuff
2020-12-26 12:44:05 -06:00

46 lines
784 B
Go

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)
}
}