Capstone/ui/config/config.go

42 lines
850 B
Go
Raw Normal View History

2023-10-28 14:42:29 -04:00
package config
import (
"github.com/spf13/viper"
)
type config struct {
2023-10-28 17:50:44 -04:00
Mongo *MongoConfig `mapstructure:"mongo"`
JwtSecret string `mapstructure:"jwt_secret"`
Env string `mapstructure:"env"`
2023-10-28 14:42:29 -04:00
}
type MongoConfig struct {
2023-10-28 17:50:44 -04:00
Uri string `mapstructure:"uri"`
EntDb string `mapstructure:"ent_db"`
EntCol string `mapstructure:"ent_col"`
2023-10-28 14:42:29 -04:00
}
var cfg *config
2023-10-28 17:50:44 -04:00
func Init() {
2023-10-28 14:42:29 -04:00
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
2023-10-28 17:50:44 -04:00
viper.AddConfigPath("/etc/capstone") // path to look for the config file in
2023-10-28 14:42:29 -04:00
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
cfg = &config{}
err = viper.Unmarshal(cfg)
if err != nil {
panic(err)
}
}
func Config() *config {
return cfg
}