style: 修改settings配置结构
This commit is contained in:
@@ -29,7 +29,7 @@ func Guardian(output bool) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
_ = recover()
|
_ = recover()
|
||||||
}()
|
}()
|
||||||
if global.Config.Settings.Interfaces == "" { //单网卡
|
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
|
||||||
if !util.Checker.NetOk(global.Transports(nil)) {
|
if !util.Checker.NetOk(global.Transports(nil)) {
|
||||||
util.Log.Println("Network down, trying to login")
|
util.Log.Println("Network down, trying to login")
|
||||||
e := Login(output, true, nil)
|
e := Login(output, true, nil)
|
||||||
@@ -37,7 +37,7 @@ func Guardian(output bool) {
|
|||||||
util.Log.Println("Error: ", e)
|
util.Log.Println("Error: ", e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if global.Config.Settings.DemoMode {
|
if global.Config.Settings.Basic.DemoMode {
|
||||||
util.Log.Println("Network ok")
|
util.Log.Println("Network ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
// Login 登录逻辑
|
// Login 登录逻辑
|
||||||
func Login(output bool, skipCheck bool, localAddr net.Addr) error {
|
func Login(output bool, skipCheck bool, localAddr net.Addr) error {
|
||||||
return BitSrun.Login(&srunTransfer.Login{
|
return BitSrun.Login(&srunTransfer.Login{
|
||||||
Demo: global.Config.Settings.DemoMode,
|
Demo: global.Config.Settings.Basic.DemoMode,
|
||||||
OutPut: output,
|
OutPut: output,
|
||||||
CheckNet: !skipCheck,
|
CheckNet: !skipCheck,
|
||||||
LoginInfo: srunTransfer.LoginInfo{
|
LoginInfo: srunTransfer.LoginInfo{
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ func readConfig() error {
|
|||||||
Enc: "srun_bx1",
|
Enc: "srun_bx1",
|
||||||
})
|
})
|
||||||
viper.SetDefault("settings", srunModels.Settings{
|
viper.SetDefault("settings", srunModels.Settings{
|
||||||
Timeout: 5,
|
Basic: srunModels.Basic{
|
||||||
|
Timeout: 5,
|
||||||
|
},
|
||||||
Daemon: srunModels.Daemon{
|
Daemon: srunModels.Daemon{
|
||||||
Path: ".autoLogin",
|
Path: ".autoLogin",
|
||||||
},
|
},
|
||||||
@@ -70,6 +72,6 @@ func init() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timeout = time.Duration(Config.Settings.Timeout) * time.Second
|
Timeout = time.Duration(Config.Settings.Basic.Timeout) * time.Second
|
||||||
initTransport()
|
initTransport()
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
util.Log.Demo = global.Config.Settings.DemoMode
|
util.Log.Demo = global.Config.Settings.Basic.DemoMode
|
||||||
util.Log.OutPut = true
|
util.Log.OutPut = true
|
||||||
defer util.Log.CatchRecover()
|
defer util.Log.CatchRecover()
|
||||||
|
|
||||||
@@ -19,10 +19,10 @@ func main() {
|
|||||||
controllers.EnterGuardian()
|
controllers.EnterGuardian()
|
||||||
} else {
|
} else {
|
||||||
//单次登录模式
|
//单次登录模式
|
||||||
if global.Config.Settings.Interfaces == "" { //单网卡
|
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
|
||||||
if err := controllers.Login(true, false, nil); err != nil {
|
if err := controllers.Login(true, false, nil); err != nil {
|
||||||
util.Log.Println("运行出错,状态异常")
|
util.Log.Println("运行出错,状态异常")
|
||||||
if global.Config.Settings.DemoMode {
|
if global.Config.Settings.Basic.DemoMode {
|
||||||
util.Log.Fatalln(err)
|
util.Log.Fatalln(err)
|
||||||
} else {
|
} else {
|
||||||
util.Log.Println(err)
|
util.Log.Println(err)
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ type Guardian struct {
|
|||||||
Duration uint `json:"duration"`
|
Duration uint `json:"duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Settings struct {
|
type Basic struct {
|
||||||
Timeout uint `json:"timeout"`
|
Timeout uint `json:"timeout"`
|
||||||
Interfaces string `json:"interfaces"`
|
Interfaces string `json:"interfaces"`
|
||||||
DemoMode bool `json:"demo_mode"`
|
DemoMode bool `json:"demo_mode"`
|
||||||
Guardian Guardian
|
}
|
||||||
Daemon Daemon
|
|
||||||
|
type Settings struct {
|
||||||
|
Basic Basic
|
||||||
|
Guardian Guardian
|
||||||
|
Daemon Daemon
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func GetInterfaceAddr() ([]srunModels.Eth, error) {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
reg, e := regexp.Compile(global.Config.Settings.Interfaces)
|
reg, e := regexp.Compile(global.Config.Settings.Basic.Interfaces)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
Log.Println("interfaces设置异常,无法解析")
|
Log.Println("interfaces设置异常,无法解析")
|
||||||
return nil, e
|
return nil, e
|
||||||
|
|||||||
Reference in New Issue
Block a user