indiescrobble/config/config.go

40 lines
750 B
Go

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()
config.BindEnv("server.port","PORT")
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
}