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.

31 lines
494 B

  1. package config
  2. import (
  3. "github.com/spf13/viper"
  4. "github.com/urfave/cli"
  5. )
  6. type Config struct {
  7. ID string
  8. Port string
  9. }
  10. var C Config
  11. func MustRead(c *cli.Context) error {
  12. viper.SetConfigType("yaml")
  13. viper.SetConfigName("config")
  14. viper.AddConfigPath(".")
  15. if c.GlobalString("config") != "" {
  16. viper.SetConfigFile(c.GlobalString("config"))
  17. }
  18. if err := viper.ReadInConfig(); err != nil {
  19. return err
  20. }
  21. if err := viper.Unmarshal(&C); err != nil {
  22. return err
  23. }
  24. return nil
  25. }