This commit is contained in:
Rogee
2024-08-30 12:38:03 +08:00
parent 1fde6ee1ff
commit e43fa0f078
26 changed files with 647 additions and 2 deletions

33
config/config.go Normal file
View 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
}