feat: add slient mode for log settings

This commit is contained in:
Revincx
2022-10-14 19:14:46 +08:00
parent fdcb530b05
commit fa2734a332
2 changed files with 10 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
package srunModels package srunModels
import "github.com/Mmx233/BitSrunLoginGo/v1/transfer" import srunTransfer "github.com/Mmx233/BitSrunLoginGo/v1/transfer"
type Daemon struct { type Daemon struct {
Enable bool `json:"enable" yaml:"enable" mapstructure:"enable"` Enable bool `json:"enable" yaml:"enable" mapstructure:"enable"`
@@ -21,6 +21,7 @@ type Basic struct {
type Log struct { type Log struct {
DebugLevel bool `json:"debug_level" yaml:"debug_level" mapstructure:"debug_level"` DebugLevel bool `json:"debug_level" yaml:"debug_level" mapstructure:"debug_level"`
SlientMode bool `json:"slient_mode" yaml:"slient_mode" mapstructure:"slient_mode"`
WriteFile bool `json:"write_file" yaml:"write_file" mapstructure:"write_file"` WriteFile bool `json:"write_file" yaml:"write_file" mapstructure:"write_file"`
FilePath string `json:"log_path" yaml:"log_path" mapstructure:"log_path"` FilePath string `json:"log_path" yaml:"log_path" mapstructure:"log_path"`
FileName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"` FileName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"`

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/Mmx233/BitSrunLoginGo/global"
"github.com/Mmx233/BitSrunLoginGo/util" "github.com/Mmx233/BitSrunLoginGo/util"
srunTransfer "github.com/Mmx233/BitSrunLoginGo/v1/transfer" srunTransfer "github.com/Mmx233/BitSrunLoginGo/v1/transfer"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -11,6 +12,7 @@ import (
func Login(c *srunTransfer.Login) error { func Login(c *srunTransfer.Login) error {
G := util.GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta) G := util.GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta)
slientMode := global.Config.Settings.Log.SlientMode
api := SrunApi{ api := SrunApi{
BaseUrl: func() string { BaseUrl: func() string {
url := "http" url := "http"
@@ -25,14 +27,18 @@ func Login(c *srunTransfer.Login) error {
var ok bool var ok bool
{ {
log.Infoln("正在检查登录状态") if !slientMode {
log.Infoln("正在检查登录状态")
}
res, e := api.GetUserInfo() res, e := api.GetUserInfo()
if e != nil { if e != nil {
return e return e
} }
err := res["error"].(string) err := res["error"].(string)
if err == "ok" { if err == "ok" {
log.Infoln("用户已登录~") if !slientMode {
log.Infoln("用户已登录~")
}
return nil return nil
} }
log.Infoln("用户似乎未登录,开始尝试登录") log.Infoln("用户似乎未登录,开始尝试登录")