chore: 变更util与global层依赖关系
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Guardian(output bool) {
|
func Guardian(output bool) {
|
||||||
global.Status.Output = output
|
util.Log.OutPut = output
|
||||||
|
|
||||||
go Daemon.DaemonChan()
|
go Daemon.DaemonChan()
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ func Guardian(output bool) {
|
|||||||
|
|
||||||
var c = make(chan bool)
|
var c = make(chan bool)
|
||||||
for {
|
for {
|
||||||
global.Status.Output = output
|
util.Log.OutPut = output
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = recover()
|
_ = recover()
|
||||||
}()
|
}()
|
||||||
if !util.Checker.NetOk() {
|
if !util.Checker.NetOk(global.Config.Settings.Timeout) {
|
||||||
util.Log.Println("Network down, trying to login")
|
util.Log.Println("Network down, trying to login")
|
||||||
_ = Login(output, true)
|
_ = Login(output, true)
|
||||||
} else {
|
} else {
|
||||||
@@ -40,7 +40,7 @@ func Guardian(output bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func EnterGuardian() {
|
func EnterGuardian() {
|
||||||
global.Status.Output = true
|
util.Log.OutPut = true
|
||||||
global.Status.Guardian = true
|
global.Status.Guardian = true
|
||||||
util.Log.Println("[Guardian mode]")
|
util.Log.Println("[Guardian mode]")
|
||||||
if global.Config.Settings.Daemon.Enable {
|
if global.Config.Settings.Daemon.Enable {
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Login(output bool, skipCheck bool) error {
|
func Login(output bool, skipCheck bool) error {
|
||||||
global.Status.Output = output
|
util.Log.OutPut = output
|
||||||
G := global.Config.Generate()
|
G := global.Config.Generate()
|
||||||
if !skipCheck {
|
if !skipCheck {
|
||||||
util.Log.Println("Step0: 检查状态…")
|
util.Log.Println("Step0: 检查状态…")
|
||||||
if util.Checker.NetOk() {
|
if util.Checker.NetOk(global.Config.Settings.Timeout) {
|
||||||
util.Log.Println("网络 ok")
|
util.Log.Println("网络 ok")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package global
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/models"
|
"github.com/Mmx233/BitSrunLoginGo/models"
|
||||||
|
"github.com/Mmx233/BitSrunLoginGo/util"
|
||||||
"github.com/Mmx233/config"
|
"github.com/Mmx233/config"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -47,4 +48,6 @@ func init() {
|
|||||||
log.Println("读取配置文件失败:\n", e.Error())
|
log.Println("读取配置文件失败:\n", e.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.Log.Demo = Config.Settings.DemoMode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import "flag"
|
import (
|
||||||
|
"flag"
|
||||||
|
)
|
||||||
|
|
||||||
var Flags struct {
|
var Flags struct {
|
||||||
Path string
|
Path string
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
var Status struct {
|
var Status struct {
|
||||||
Output bool
|
|
||||||
Guardian bool
|
Guardian bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/global"
|
|
||||||
"github.com/Mmx233/tool"
|
"github.com/Mmx233/tool"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -10,11 +9,11 @@ type checker struct{}
|
|||||||
|
|
||||||
var Checker checker
|
var Checker checker
|
||||||
|
|
||||||
func (checker) NetOk() bool {
|
func (checker) NetOk(timeout uint) bool {
|
||||||
h, _, e := tool.HTTP.GetBytes(&tool.GetRequest{
|
h, _, e := tool.HTTP.GetBytes(&tool.GetRequest{
|
||||||
Url: "https://www.baidu.com/",
|
Url: "https://www.baidu.com/",
|
||||||
Redirect: false,
|
Redirect: false,
|
||||||
Timeout: time.Duration(global.Config.Settings.Timeout) * time.Second,
|
Timeout: time.Duration(timeout) * time.Second,
|
||||||
})
|
})
|
||||||
if e != nil || h.Get("Location") != "" {
|
if e != nil || h.Get("Location") != "" {
|
||||||
return false
|
return false
|
||||||
|
|||||||
11
util/log.go
11
util/log.go
@@ -2,7 +2,6 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/global"
|
|
||||||
"github.com/Mmx233/tool"
|
"github.com/Mmx233/tool"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -13,12 +12,14 @@ import (
|
|||||||
|
|
||||||
type loG struct {
|
type loG struct {
|
||||||
timeStamp string
|
timeStamp string
|
||||||
|
Demo bool
|
||||||
|
OutPut bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var Log loG
|
var Log loG
|
||||||
|
|
||||||
func (*loG) WriteLog(name string, a ...interface{}) {
|
func (c *loG) WriteLog(name string, a ...interface{}) {
|
||||||
if !global.Config.Settings.DemoMode {
|
if !c.Demo {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
@@ -47,7 +48,7 @@ func (c *loG) genTimeStamp() {
|
|||||||
func (c *loG) Println(a ...interface{}) {
|
func (c *loG) Println(a ...interface{}) {
|
||||||
c.genTimeStamp()
|
c.genTimeStamp()
|
||||||
c.WriteLog("Login-"+c.timeStamp+".log", a...)
|
c.WriteLog("Login-"+c.timeStamp+".log", a...)
|
||||||
if !global.Status.Output {
|
if !c.OutPut {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println(a...)
|
log.Println(a...)
|
||||||
@@ -56,7 +57,7 @@ func (c *loG) Println(a ...interface{}) {
|
|||||||
func (c *loG) Fatalln(a ...interface{}) {
|
func (c *loG) Fatalln(a ...interface{}) {
|
||||||
c.genTimeStamp()
|
c.genTimeStamp()
|
||||||
c.WriteLog("LoginError-"+c.timeStamp+".log", a...)
|
c.WriteLog("LoginError-"+c.timeStamp+".log", a...)
|
||||||
if !global.Status.Output {
|
if !c.OutPut {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Fatalln(a...)
|
log.Fatalln(a...)
|
||||||
|
|||||||
Reference in New Issue
Block a user