feat: 重构配置层,添加 json 支持
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/global"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||
"time"
|
||||
|
||||
"github.com/Mmx233/BitSrunLoginGo/tools"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func Guardian() {
|
||||
log.Infoln("[以守护模式启动]")
|
||||
|
||||
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
|
||||
GuardianDuration := time.Duration(config.Settings.Guardian.Duration) * time.Second
|
||||
|
||||
var c = make(chan bool)
|
||||
for {
|
||||
@@ -20,13 +20,13 @@ func Guardian() {
|
||||
defer func() {
|
||||
_ = recover()
|
||||
}()
|
||||
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
|
||||
if config.Settings.Basic.Interfaces == "" { //单网卡
|
||||
e := Login(nil, true)
|
||||
if e != nil {
|
||||
log.Errorln("登录出错: ", e)
|
||||
}
|
||||
} else { //多网卡
|
||||
interfaces, e := tools.GetInterfaceAddr(global.Config.Settings.Basic.Interfaces)
|
||||
interfaces, e := tools.GetInterfaceAddr(config.Settings.Basic.Interfaces)
|
||||
if e == nil {
|
||||
for _, eth := range interfaces {
|
||||
log.Debugf("使用 %s 网口登录 ", eth.Name)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/global"
|
||||
"errors"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns"
|
||||
"github.com/Mmx233/BitSrunLoginGo/pkg/srun"
|
||||
"github.com/Mmx233/BitSrunLoginGo/tools"
|
||||
@@ -14,23 +16,23 @@ func Login(eth *tools.Eth, debugOutput bool) error {
|
||||
// 登录配置初始化
|
||||
httpClient := tools.HttpPackSelect(eth).Client
|
||||
srunClient := srun.New(&srun.Conf{
|
||||
Https: global.Config.Settings.Basic.Https,
|
||||
Https: config.Settings.Basic.Https,
|
||||
LoginInfo: srun.LoginInfo{
|
||||
Form: global.Config.Form,
|
||||
Meta: global.Config.Meta,
|
||||
Form: *config.Form,
|
||||
Meta: *config.Meta,
|
||||
},
|
||||
Client: httpClient,
|
||||
})
|
||||
|
||||
// 嗅探 acid
|
||||
if global.Flags.AutoAcid {
|
||||
if flags.AutoAcid {
|
||||
log.Debugln("开始嗅探 acid")
|
||||
acid, e := srunClient.DetectAcid()
|
||||
if e != nil {
|
||||
if e == srun.ErrAcidCannotFound {
|
||||
acid, err := srunClient.DetectAcid()
|
||||
if err != nil {
|
||||
if errors.Is(err, srun.ErrAcidCannotFound) {
|
||||
log.Errorln("找不到 acid,使用配置 acid")
|
||||
} else {
|
||||
log.Errorf("嗅探 acid 失败,使用配置 acid: %v", e)
|
||||
log.Errorf("嗅探 acid 失败,使用配置 acid: %v", err)
|
||||
}
|
||||
} else {
|
||||
log.Debugf("使用嗅探 acid: %s", acid)
|
||||
@@ -60,7 +62,7 @@ func Login(eth *tools.Eth, debugOutput bool) error {
|
||||
if online {
|
||||
output("已登录~")
|
||||
|
||||
if global.Config.Settings.DDNS.Enable && global.Config.Settings.Guardian.Enable && ipLast != ip {
|
||||
if config.Settings.DDNS.Enable && config.Settings.Guardian.Enable && ipLast != ip {
|
||||
if ddns(ip, httpClient) == nil {
|
||||
ipLast = ip
|
||||
}
|
||||
@@ -76,7 +78,7 @@ func Login(eth *tools.Eth, debugOutput bool) error {
|
||||
|
||||
log.Infoln("登录成功~")
|
||||
|
||||
if global.Config.Settings.DDNS.Enable {
|
||||
if config.Settings.DDNS.Enable {
|
||||
_ = ddns(ip, httpClient)
|
||||
}
|
||||
}
|
||||
@@ -88,11 +90,11 @@ var ipLast string
|
||||
|
||||
func ddns(ip string, httpClient *http.Client) error {
|
||||
return dns.Run(&dns.Config{
|
||||
Provider: global.Config.Settings.DDNS.Provider,
|
||||
Provider: config.Settings.DDNS.Provider,
|
||||
IP: ip,
|
||||
Domain: global.Config.Settings.DDNS.Domain,
|
||||
TTL: global.Config.Settings.DDNS.TTL,
|
||||
Conf: global.Config.Settings.DDNS.Config,
|
||||
Domain: config.Settings.DDNS.Domain,
|
||||
TTL: config.Settings.DDNS.TTL,
|
||||
Conf: config.Settings.DDNS.Config,
|
||||
Http: httpClient,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user