package config import ( "github.com/pkg/errors" "github.com/spf13/viper" ) var C *Config type Config struct { Phone string `mapstructure:"phone"` AppID int `mapstructure:"app_id"` AppHash string `mapstructure:"app_hash"` BotToken string `mapstructure:"bot_token"` SessionFile string `mapstructure:"session_file"` LogFile string `mapstructure:"log_file"` MaxSize string `mapstructure:"max_size"` DSN string `mapstructure:"dsn"` Output string `mapstructure:"output"` } // GetMaxSize func (c *Config) GetMaxSize() uint { // parse 50mb to 50 * 1024 * 1024 return viper.GetSizeInBytes("max_size") } func Load(path string) error { // Load the config file viper.SetConfigFile(path) viper.AutomaticEnv() if err := viper.ReadInConfig(); err != nil { return errors.Wrapf(err, "failed to read the config file %s", path) } if err := viper.Unmarshal(&C); err != nil { return errors.Wrapf(err, "failed to unmarshal the config %s", path) } return nil }