refactor socks5 proxy and cron config

This commit is contained in:
iyear 2021-06-19 13:03:38 +08:00
parent 89946ffd62
commit 9a919c5399
2 changed files with 10 additions and 4 deletions

View File

@ -56,14 +56,16 @@ func BotStart() {
}
//set socks5
if config.Socks5 != "" {
fmt.Println("Proxy:" + config.Socks5)
fmt.Println("Proxy: " + config.Socks5)
dialer, err := proxy.SOCKS5("tcp", config.Socks5, nil, proxy.Direct)
if err != nil {
zap.S().Errorw("failed to make dialer", "error", err, "socks5", config.Socks5)
zap.S().Errorw("failed to get dialer",
"error", err, "proxy", config.Socks5)
}
httpTransport := &http.Transport{}
httpClient := &http.Client{Transport: httpTransport}
httpTransport.Dial = dialer.Dial
httpClient := &http.Client{Transport: httpTransport}
botSetting.Client = httpClient
}
//create bot

View File

@ -41,7 +41,11 @@ func InitConfig() {
zap.S().Errorw("failed to read config", "error", err)
}
BotToken = viper.GetString("bot_token")
Cron = viper.GetString("cron")
Socks5 = viper.GetString("socks5")
//if Socks5[:5] != "socks5" {
// Socks5 = "socks5://" + Socks5
//}
viper.SetDefault("errlimit", 5)
viper.SetDefault("bindmax", 5)
@ -49,7 +53,7 @@ func InitConfig() {
BindMaxNum = viper.GetInt("bindmax")
MaxErrTimes = viper.GetInt("errlimit")
Notice = viper.GetString("notice")
Cron = viper.GetString("cron")
MaxGoroutines = viper.GetInt("goroutine")
Admins = getAdmins()