init
This commit is contained in:
33
config/config.go
Normal file
33
config/config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user