feat: 添加更多debug日志、checker url可控化
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
func Guardian(output bool) {
|
func Guardian(output bool) {
|
||||||
util.Log.OutPut = output
|
util.Log.OutPut = output
|
||||||
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
|
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
|
||||||
|
util.Checker.SetUrl(global.Config.Settings.Basic.NetCheckUrl)
|
||||||
|
|
||||||
if global.Config.Settings.Daemon.Enable {
|
if global.Config.Settings.Daemon.Enable {
|
||||||
go Daemon.DaemonChan()
|
go Daemon.DaemonChan()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func Login(output bool, skipCheck bool, localAddr net.Addr) error {
|
|||||||
WriteLog: global.Config.Settings.Debug.WriteLog,
|
WriteLog: global.Config.Settings.Debug.WriteLog,
|
||||||
OutPut: output,
|
OutPut: output,
|
||||||
CheckNet: !skipCheck,
|
CheckNet: !skipCheck,
|
||||||
|
CheckNetUrl: global.Config.Settings.Basic.NetCheckUrl,
|
||||||
LoginInfo: srunTransfer.LoginInfo{
|
LoginInfo: srunTransfer.LoginInfo{
|
||||||
Form: &global.Config.Form,
|
Form: &global.Config.Form,
|
||||||
Meta: &global.Config.Meta,
|
Meta: &global.Config.Meta,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func readConfig() error {
|
|||||||
viper.SetDefault("settings", srunModels.Settings{
|
viper.SetDefault("settings", srunModels.Settings{
|
||||||
Basic: srunModels.Basic{
|
Basic: srunModels.Basic{
|
||||||
Timeout: 5,
|
Timeout: 5,
|
||||||
|
NetCheckUrl: "https://www.baidu.com/",
|
||||||
},
|
},
|
||||||
Daemon: srunModels.Daemon{
|
Daemon: srunModels.Daemon{
|
||||||
Path: ".autoLogin",
|
Path: ".autoLogin",
|
||||||
@@ -45,21 +46,21 @@ func readConfig() error {
|
|||||||
if !tool.File.Exists(Flags.Path) {
|
if !tool.File.Exists(Flags.Path) {
|
||||||
e := viper.WriteConfigAs(Flags.Path)
|
e := viper.WriteConfigAs(Flags.Path)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Println("生成配置文件失败:", e)
|
log.Println("[init] 生成配置文件失败:", e)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
log.Println("已生成配置文件,请编辑 '" + Flags.Path + "' 然后重试")
|
log.Println("[init] 已生成配置文件,请编辑 '" + Flags.Path + "' 然后重试")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取配置文件
|
//读取配置文件
|
||||||
viper.SetConfigFile(Flags.Path)
|
viper.SetConfigFile(Flags.Path)
|
||||||
if e := viper.ReadInConfig(); e != nil {
|
if e := viper.ReadInConfig(); e != nil {
|
||||||
log.Println("读取配置文件失败:", e)
|
log.Println("[init] 读取配置文件失败:", e)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if e := viper.Unmarshal(&Config); e != nil {
|
if e := viper.Unmarshal(&Config); e != nil {
|
||||||
log.Println("解析配置文件失败:", e)
|
log.Println("[init] 解析配置文件失败:", e)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +75,7 @@ func init() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//初始化常变量
|
||||||
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
||||||
initTransport()
|
initTransport()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type Basic struct {
|
|||||||
Timeout uint `json:"timeout" yaml:"timeout" mapstructure:"timeout"`
|
Timeout uint `json:"timeout" yaml:"timeout" mapstructure:"timeout"`
|
||||||
Interfaces string `json:"interfaces" yaml:"interfaces" mapstructure:"interfaces"`
|
Interfaces string `json:"interfaces" yaml:"interfaces" mapstructure:"interfaces"`
|
||||||
SkipNetCheck bool `json:"skip_net_check" yaml:"skip_net_check" mapstructure:"skip_net_check"`
|
SkipNetCheck bool `json:"skip_net_check" yaml:"skip_net_check" mapstructure:"skip_net_check"`
|
||||||
|
NetCheckUrl string `json:"net_check_url" yaml:"net_check_url" mapstructure:"net_check_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
|
|||||||
@@ -5,14 +5,28 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type checker struct{}
|
type checker struct {
|
||||||
|
url string
|
||||||
|
set bool
|
||||||
|
}
|
||||||
|
|
||||||
var Checker checker
|
var Checker = checker{
|
||||||
|
url: "https://www.baidu.com/",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *checker) SetUrl(url string) {
|
||||||
|
if a.set {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.url = url
|
||||||
|
a.set = true
|
||||||
|
}
|
||||||
|
|
||||||
// NetOk 网络状况检查
|
// NetOk 网络状况检查
|
||||||
func (a *checker) NetOk(transport *http.Transport) bool {
|
func (a *checker) NetOk(transport *http.Transport) bool {
|
||||||
|
Log.Debug("GET ", a.url)
|
||||||
res, e := tool.HTTP.GetReader(&tool.GetRequest{
|
res, e := tool.HTTP.GetReader(&tool.GetRequest{
|
||||||
Url: "https://www.baidu.com/",
|
Url: a.url,
|
||||||
Redirect: false,
|
Redirect: false,
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (c *loG) Init(debug, logFile, outPut bool, path string) error {
|
|||||||
c.timeStamp = time.Now().Format("2006.01.02-15.04.05")
|
c.timeStamp = time.Now().Format("2006.01.02-15.04.05")
|
||||||
|
|
||||||
//日志路径初始化与处理
|
//日志路径初始化与处理
|
||||||
if c.DebugMode {
|
if c.DebugMode && c.WriteFile {
|
||||||
if !strings.HasSuffix(path, "/") {
|
if !strings.HasSuffix(path, "/") {
|
||||||
path += "/"
|
path += "/"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
|
|
||||||
G := util.GenerateLoginInfo(c.Https, c.LoginInfo.Form, c.LoginInfo.Meta)
|
G := util.GenerateLoginInfo(c.Https, c.LoginInfo.Form, c.LoginInfo.Meta)
|
||||||
if c.CheckNet {
|
if c.CheckNet {
|
||||||
|
if c.CheckNetUrl != "" {
|
||||||
|
util.Checker.SetUrl(c.CheckNetUrl)
|
||||||
|
}
|
||||||
util.Log.Info("Step0: 检查状态…")
|
util.Log.Info("Step0: 检查状态…")
|
||||||
if util.Checker.NetOk(c.Transport) {
|
if util.Checker.NetOk(c.Transport) {
|
||||||
util.Log.Info("网络 ok")
|
util.Log.Info("网络 ok")
|
||||||
@@ -35,9 +38,10 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
} else if G.Ip, e = util.GetIp(body); e != nil {
|
} else if G.Ip, e = util.GetIp(body); e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
util.Log.Debug("ip: ", G.Ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.Log.Info("Step2: 正在获取Token")
|
util.Log.Info("Step2: 正在获取token")
|
||||||
{
|
{
|
||||||
util.Log.Debug("GET ", G.UrlGetChallengeApi)
|
util.Log.Debug("GET ", G.UrlGetChallengeApi)
|
||||||
if _, data, e := tool.HTTP.GetString(&tool.GetRequest{
|
if _, data, e := tool.HTTP.GetString(&tool.GetRequest{
|
||||||
@@ -54,6 +58,7 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
} else if G.Token, e = util.GetToken(data); e != nil {
|
} else if G.Token, e = util.GetToken(data); e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
util.Log.Debug("token: ", G.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.Log.Info("Step3: 执行登录…")
|
util.Log.Info("Step3: 执行登录…")
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type Login struct {
|
|||||||
OutPut bool
|
OutPut bool
|
||||||
//登陆前是否检查网络,只在离线时登录
|
//登陆前是否检查网络,只在离线时登录
|
||||||
CheckNet bool
|
CheckNet bool
|
||||||
|
CheckNetUrl string
|
||||||
//登录参数,不可缺省
|
//登录参数,不可缺省
|
||||||
LoginInfo LoginInfo
|
LoginInfo LoginInfo
|
||||||
Transport *http.Transport
|
Transport *http.Transport
|
||||||
|
|||||||
Reference in New Issue
Block a user