feat: 重构配置层,添加 json 支持

This commit is contained in:
Mmx233
2023-08-28 22:03:03 +08:00
parent 2a098e00dd
commit 6f283a93f5
19 changed files with 318 additions and 272 deletions

View File

@@ -1,32 +1,33 @@
package main
import (
"github.com/Mmx233/BitSrunLoginGo/internal/config"
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
"github.com/Mmx233/BitSrunLoginGo/internal/controllers"
"github.com/Mmx233/BitSrunLoginGo/internal/global"
"github.com/Mmx233/BitSrunLoginGo/tools"
log "github.com/sirupsen/logrus"
"net"
)
func main() {
if global.Config.Settings.Guardian.Enable {
if config.Settings.Guardian.Enable {
//进入守护模式
controllers.Guardian()
} else {
//登录流程
var err error
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
if config.Settings.Basic.Interfaces == "" { //单网卡
var eth *tools.Eth
if global.Flags.Interface != "" {
netEth, e := net.InterfaceByName(global.Flags.Interface)
if flags.Interface != "" {
netEth, e := net.InterfaceByName(flags.Interface)
if e != nil {
log.Warnf("获取指定网卡 %s 失败,使用默认网卡: %v", global.Flags.Interface, e)
log.Warnf("获取指定网卡 %s 失败,使用默认网卡: %v", flags.Interface, e)
} else {
eth, e = tools.ConvertInterface(*netEth)
if e != nil {
log.Warnf("获取指定网卡 %s ip 地址失败,使用默认网卡: %v", global.Flags.Interface, e)
log.Warnf("获取指定网卡 %s ip 地址失败,使用默认网卡: %v", flags.Interface, e)
} else if eth == nil {
log.Warnf("指定网卡 %s 无可用 ip 地址,使用默认网卡", global.Flags.Interface)
log.Warnf("指定网卡 %s 无可用 ip 地址,使用默认网卡", flags.Interface)
} else {
log.Debugf("使用指定网卡 %s ip: %s", eth.Name, eth.Addr.String())
}
@@ -34,14 +35,14 @@ func main() {
}
if err = controllers.Login(eth, false); err != nil {
log.Errorln("登录出错: ", err)
if !global.Config.Settings.Log.DebugLevel {
if !config.Settings.Log.DebugLevel {
log.Infoln("开启调试日志debug_level获取详细信息")
}
return
}
} else { //多网卡
log.Infoln("多网卡模式")
interfaces, _ := tools.GetInterfaceAddr(global.Config.Settings.Basic.Interfaces)
interfaces, _ := tools.GetInterfaceAddr(config.Settings.Basic.Interfaces)
for _, eth := range interfaces {
log.Infoln("使用网卡: ", eth.Name)
if err = controllers.Login(&eth, false); err != nil {