indiescrobble/config/config.go

37 lines
709 B
Go
Raw Normal View History

2022-01-30 16:05:54 +00:00
package config
import (
"log"
"path/filepath"
"github.com/spf13/viper"
)
var config *viper.Viper
// Init is an exported method that takes the environment starts the viper
// (external lib) and returns the configuration struct.
func Init(env string) {
var err error
config = viper.New()
config.SetConfigType("yaml")
config.SetConfigName(env)
config.AddConfigPath("../config/")
config.AddConfigPath("config/")
err = config.ReadInConfig()
if err != nil {
log.Fatal("error on parsing configuration file")
}
}
func relativePath(basedir string, path *string) {
p := *path
if len(p) > 0 && p[0] != '/' {
*path = filepath.Join(basedir, p)
}
}
func GetConfig() *viper.Viper {
return config
}