improve: pass logger instead of using global logger

This commit is contained in:
Mmx
2024-09-24 23:36:09 +08:00
parent e1ff68cfc2
commit 78a1b2662d
15 changed files with 163 additions and 126 deletions

View File

@@ -5,12 +5,13 @@ import (
"time"
"github.com/Mmx233/BitSrunLoginGo/tools"
log "github.com/sirupsen/logrus"
)
// Guardian 守护模式逻辑
func Guardian() {
log.Infoln("[以守护模式启动]")
logger := config.Logger
logger.Infoln("[以守护模式启动]")
GuardianDuration := time.Duration(config.Settings.Guardian.Duration) * time.Second
@@ -20,16 +21,16 @@ func Guardian() {
if config.Settings.Basic.Interfaces == "" { //单网卡
err := Login(nil, true)
if err != nil {
log.Errorln("登录出错: ", err)
logger.Errorln("登录出错: ", err)
}
} else { //多网卡
interfaces, err := tools.GetInterfaceAddr(config.Settings.Basic.Interfaces)
interfaces, err := tools.GetInterfaceAddr(logger, config.Settings.Basic.Interfaces)
if err == nil {
for _, eth := range interfaces {
log.Debugf("使用 %s 网口登录 ", eth.Name)
logger.Debugf("使用 %s 网口登录 ", eth.Name)
err = Login(&eth, true)
if err != nil {
log.Errorln("网口 ", eth.Name+" 登录出错: ", err)
logger.Errorln("网口 ", eth.Name+" 登录出错: ", err)
}
}
}