From b4fffa704dfea42f01c27986a3faf0d6d4ee6da9 Mon Sep 17 00:00:00 2001 From: rootphantomer Date: Wed, 12 Oct 2022 17:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E8=BE=93=E5=87=BA=E5=86=85=E5=AE=B9=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E6=9B=B4=E5=8A=A0=E8=AF=A6=E7=BB=86=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E5=B7=A5=E5=85=B7=E6=9C=AC=E8=BA=AB=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++++-- main.go | 2 +- utils/LoadJson.go | 19 +++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c1e5dd1..44d831d 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,15 @@ rust 项目代码 移步这里—— ## 更新日志 +- 2022-10-12 v2.0.3: + + - 优化代码逻辑 + - 优化代码报错输出内容,方便更加详细的判断是服务器错误还是工具本身的代码错误 + - 2022-10-02 v2.0.2: - - 修复search空格被吃掉的问题 - - 增加命令后颜色输出 + - 修复search空格被吃掉的问题 + - 增加命令后颜色输出 - 2022-09-28 v2.0.1: diff --git a/main.go b/main.go index c112076..8c8f880 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func action(num int) { } switch strings.ToLower(hflag.GetString("option")) { case "version": - successColor.Println("version:2.0.2") + successColor.Println("version:2.0.3") case "init": if num < 3 { errorColor.Println("!!!!token is empty !!!!") diff --git a/utils/LoadJson.go b/utils/LoadJson.go index e144cb8..7367dab 100644 --- a/utils/LoadJson.go +++ b/utils/LoadJson.go @@ -13,12 +13,14 @@ package utils import ( "encoding/json" "fmt" + "os" ) func RespLoadJson[T any](body string) (respjson T) { if err := json.Unmarshal([]byte(body), &respjson); err != nil { fmt.Println(body) - panic(err) + //panic(err) + os.Exit(0) } return } @@ -28,9 +30,18 @@ func InfoLoadJson(body string) (data map[string]interface{}, user map[string]int var infomapjson map[string]interface{} if err := json.Unmarshal([]byte(body), &infomapjson); err != nil { fmt.Println(body) - panic(err) + //panic(err) + os.Exit(0) + } + data, ok := infomapjson["data"].(map[string]interface{}) + if !ok { + fmt.Println(infomapjson) + os.Exit(0) + } + user, ok = data["user"].(map[string]interface{}) + if !ok { + fmt.Println(infomapjson) + os.Exit(0) } - data = infomapjson["data"].(map[string]interface{}) - user = data["user"].(map[string]interface{}) return }