You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
878 B

package config
import (
"strings"
"github.com/spf13/viper"
"github.com/urfave/cli"
)
type Config struct {
Server struct {
ServiceApi string
AdminApi string
}
Mongodb struct {
Url string
Database string
}
}
var C Config
func MustRead(c *cli.Context) error {
viper.SetConfigType("yaml")
viper.SetConfigName("config")
viper.AddConfigPath(".") // adding home directory as first search path
viper.SetEnvPrefix("gogame") // so viper.AutomaticEnv will get matching envvars starting with O2M_
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
if c.GlobalString("config") != "" {
viper.SetConfigFile(c.GlobalString("config"))
}
if err := viper.ReadInConfig(); err != nil {
return err
}
if err := viper.Unmarshal(&C); err != nil {
return err
}
return nil
}