refactor: remove slient mode and improve debug level log output
This commit is contained in:
@@ -37,9 +37,7 @@ func Guardian() {
|
|||||||
interfaces, e := util.GetInterfaceAddr()
|
interfaces, e := util.GetInterfaceAddr()
|
||||||
if e == nil {
|
if e == nil {
|
||||||
for _, eth := range interfaces {
|
for _, eth := range interfaces {
|
||||||
if !global.Config.Settings.Log.SlientMode {
|
log.Debugln("登录使用的网口: " + eth.Name)
|
||||||
log.Infoln("登录使用的网口: " + eth.Name)
|
|
||||||
}
|
|
||||||
e = Login(eth.Addr)
|
e = Login(eth.Addr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Errorln("网口 ", eth.Name+" 登录失败: ", e)
|
log.Errorln("网口 ", eth.Name+" 登录失败: ", e)
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -25,7 +25,7 @@ func main() {
|
|||||||
log.Debugln("多网卡模式")
|
log.Debugln("多网卡模式")
|
||||||
interfaces, _ := util.GetInterfaceAddr()
|
interfaces, _ := util.GetInterfaceAddr()
|
||||||
for _, eth := range interfaces {
|
for _, eth := range interfaces {
|
||||||
log.Infoln("网卡: ", eth.Name)
|
log.Debugln("使用网卡: ", eth.Name)
|
||||||
if err = controllers.Login(eth.Addr); err != nil {
|
if err = controllers.Login(eth.Addr); err != nil {
|
||||||
log.Errorln("运行出错,状态异常: ", err)
|
log.Errorln("运行出错,状态异常: ", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ 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"`
|
||||||
|
|||||||
22
v1/login.go
22
v1/login.go
@@ -3,7 +3,6 @@ package BitSrun
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"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,7 +10,6 @@ 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"
|
||||||
@@ -26,25 +24,19 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
{
|
{
|
||||||
if !slientMode {
|
log.Debugln("正在检查登录状态")
|
||||||
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" {
|
||||||
if !slientMode {
|
log.Debugln("用户已登录~")
|
||||||
log.Infoln("用户已登录~")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Infoln("检测到用户未登录,开始尝试登录...")
|
log.Infoln("检测到用户未登录,开始尝试登录...")
|
||||||
|
|
||||||
if !slientMode {
|
log.Debugln("正在获取客户端 IP")
|
||||||
log.Infoln("正在获取客户端 IP")
|
|
||||||
}
|
|
||||||
var ip interface{}
|
var ip interface{}
|
||||||
ip, ok = res["client_ip"]
|
ip, ok = res["client_ip"]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -57,9 +49,7 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
log.Debugln("ip: ", G.Ip)
|
log.Debugln("ip: ", G.Ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slientMode {
|
log.Debugln("正在获取 Token")
|
||||||
log.Infoln("正在获取 Token")
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
res, e := api.GetChallenge(G.Form.UserName, G.Ip)
|
res, e := api.GetChallenge(G.Form.UserName, G.Ip)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@@ -74,9 +64,7 @@ func Login(c *srunTransfer.Login) error {
|
|||||||
log.Debugln("token: ", G.Token)
|
log.Debugln("token: ", G.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slientMode {
|
log.Debugln("发送登录请求")
|
||||||
log.Infoln("发送登录请求")
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
info, e := json.Marshal(map[string]string{
|
info, e := json.Marshal(map[string]string{
|
||||||
"username": G.Form.UserName,
|
"username": G.Form.UserName,
|
||||||
|
|||||||
Reference in New Issue
Block a user