All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// AppConfig represents the config flags for the base application.
|
|
type AppConfig struct {
|
|
Environment string
|
|
Port string
|
|
}
|
|
|
|
// DBConfig is the config for the DB connection.
|
|
type DBConfig struct {
|
|
Type string
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Database string
|
|
}
|
|
|
|
// Conf represents the overall configuration of the application.
|
|
type Conf struct {
|
|
App AppConfig
|
|
Db DBConfig
|
|
}
|
|
|
|
// GetConf returns config values
|
|
func GetConf(filename string) *Conf {
|
|
|
|
cnf := &Conf{
|
|
App: AppConfig{
|
|
Environment: "local",
|
|
Port: "8080",
|
|
},
|
|
}
|
|
|
|
vv := viper.New()
|
|
vv.SetConfigName(filename)
|
|
vv.SetConfigType("yaml")
|
|
vv.AddConfigPath(".")
|
|
log.Printf("Initialising config with filename %s", filename)
|
|
|
|
err := vv.ReadInConfig()
|
|
if err != nil {
|
|
log.Fatal("Could not load config file: \n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
err = vv.Unmarshal(&cnf)
|
|
if err != nil {
|
|
log.Fatal("Could not read config file into struct: \n", err)
|
|
os.Exit(1)
|
|
}
|
|
return cnf
|
|
}
|