gogmagog/config/config.go
Deepak 3ea8603368
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Adds user table and adds support for config flag to drop DB on restart
2021-01-11 20:15:36 -06:00

73 lines
1.3 KiB
Go

package config
import (
"log"
"github.com/spf13/viper"
)
// AppConfig represents the config flags for the base application.
type AppConfig struct {
Environment string
Port string
Timezone string
}
// DBConfig is the config for the DB connection.
type DBConfig struct {
Type string
Host string
Port string
User string
Password string
Database string
DropOnStart bool
}
// Conf represents the overall configuration of the application.
type Conf struct {
App AppConfig
Db DBConfig
}
func createDefaultConf() *Conf {
cnf := &Conf{
App: AppConfig{
Environment: "local",
Port: "8080",
Timezone: "America/New_York",
},
Db: DBConfig{
Type: "postgres",
Host: "localhost",
Port: "5432",
User: "<user>",
Password: "<password>",
Database: "gogmagog",
DropOnStart: false,
},
}
return cnf
}
// GetConf returns config values
func GetConf(filename string) (*Conf, error) {
cnf := createDefaultConf()
vv := viper.New()
vv.SetConfigName(filename)
vv.SetConfigType("yaml")
vv.AddConfigPath(".")
err := vv.ReadInConfig()
if err != nil {
log.Print("Could not load config file: \n", err)
return nil, err
}
vv.Unmarshal(&cnf)
return cnf, nil
}