package config
|
|
|
|
import (
|
|
"github.com/spf13/viper"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
type Config struct {
|
|
ID string
|
|
Port string
|
|
}
|
|
|
|
var C Config
|
|
|
|
func MustRead(c *cli.Context) error {
|
|
viper.SetConfigType("yaml")
|
|
viper.SetConfigName("config")
|
|
viper.AddConfigPath(".")
|
|
|
|
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
|
|
}
|