diff --git a/controllers/daemon.go b/controllers/daemon.go index 3a6093d..eea506b 100644 --- a/controllers/daemon.go +++ b/controllers/daemon.go @@ -16,7 +16,7 @@ type daemon struct { var Daemon = daemon{ Mark: fmt.Sprint(time.Now().UnixNano()), - Path: ".autoLoginDaemon", + Path: global.Config.Settings.Daemon.Path, } func init() { diff --git a/controllers/guardian.go b/controllers/guardian.go index b30e658..151fa19 100644 --- a/controllers/guardian.go +++ b/controllers/guardian.go @@ -35,7 +35,7 @@ func Guardian(output bool) { c <- false }() <-c - time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second) + time.Sleep(time.Duration(global.Config.Settings.Guardian.Duration) * time.Second) } } @@ -43,7 +43,7 @@ func EnterGuardian() { global.Status.Output = true global.Status.Guardian = true util.Log.Println("[Guardian mode]") - if global.Config.Settings.Daemon { + if global.Config.Settings.Daemon.Enable { if err := exec.Command(os.Args[0], "-daemon").Start(); err != nil { util.Log.Fatalln(err) } diff --git a/global/config.go b/global/config.go index fda7dc2..61ada96 100644 --- a/global/config.go +++ b/global/config.go @@ -16,7 +16,7 @@ func init() { if e := config.Load(config.Options{ Config: &Config, Default: &models.Config{ - From: models.LoginForm{ + Form: models.LoginForm{ Domain: "www.msftconnecttest.com", UserType: "cmcc", }, @@ -28,6 +28,12 @@ func init() { }, Settings: models.Settings{ Timeout: 1, + Daemon: models.Daemon{ + Path: ".autoLogin", + }, + Guardian: models.Guardian{ + Duration: 300, + }, }, }, Path: Flags.Path, diff --git a/main.go b/main.go index c8fd27e..5a3b38b 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( func main() { defer util.Log.CatchRecover() - if global.Config.Settings.Guardian != 0 { + if global.Config.Settings.Guardian.Enable { controllers.EnterGuardian() } else if err := controllers.Login(true, false); err != nil { util.Log.Println("运行出错,状态异常") diff --git a/models/config.go b/models/config.go index b568213..7e0533e 100644 --- a/models/config.go +++ b/models/config.go @@ -1,10 +1,20 @@ package models +type Daemon struct { + Enable bool `json:"enable"` + Path string `json:"path"` +} + +type Guardian struct { + Enable bool `json:"enable"` + Duration uint `json:"duration"` +} + type Settings struct { Timeout uint `json:"timeout"` DemoMode bool `json:"demo_mode"` - Guardian uint `json:"guardian"` - Daemon bool `json:"daemon"` + Guardian Guardian + Daemon Daemon } type Config struct {