feat: 重构配置层,添加 json 支持
This commit is contained in:
@@ -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