From 01dfd9dc8de7b19f9dfa4284722e01bbd5837801 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 19 一月 2024 09:10:30 +0800 Subject: [PATCH] replace json to json-iterator --- dicApi.go | 41 ++++++++++++++++++++++------------------- 1 files changed, 22 insertions(+), 19 deletions(-) diff --git a/dicApi.go b/dicApi.go index d59c191..0c977b6 100644 --- a/dicApi.go +++ b/dicApi.go @@ -2,70 +2,73 @@ import ( "basic.com/pubsub/protomsg.git" - json "github.com/json-iterator/go" + jsoniter "github.com/json-iterator/go" ) type DicApi struct { - } -func (api DicApi) FindByType(dicType string) (bool,interface{}) { +func (api DicApi) FindByType(dicType string) (bool, interface{}) { url := DATA_URL_PREFIX + "/dictionary/findByType" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) paramMap := make(map[string]string) paramMap["type"] = dicType respBody, err := client.DoGetRequest(url, paramMap, nil) - if err !=nil { - return false,nil + if err != nil { + return false, nil } var res Result + var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(respBody, &res); err != nil { logPrint(err) - return false,nil + return false, nil } - return res.Success,res.Data + return res.Success, res.Data } -func (api DicApi) FindByParentId(parentId string) (bool,interface{}){ +func (api DicApi) FindByParentId(parentId string) (bool, interface{}) { url := DATA_URL_PREFIX + "/dictionary/findByParentId" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) paramMap := make(map[string]string) paramMap["parentId"] = parentId respBody, err := client.DoGetRequest(url, paramMap, nil) - if err !=nil { - return false,nil + if err != nil { + return false, nil } var res Result + var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(respBody, &res); err != nil { logPrint(err) - return false,nil + return false, nil } - return res.Success,res.Data + return res.Success, res.Data } -func (api DicApi) ListByType(typ string) (flag bool,list []protomsg.Dic){ +func (api DicApi) ListByType(typ string) (flag bool, list []protomsg.Dic) { url := DATA_URL_PREFIX + "/dictionary/listByType" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) paramMap := make(map[string]string) paramMap["type"] = typ respBody, err := client.DoGetRequest(url, paramMap, nil) - if err !=nil { - return false,nil + if err != nil { + return false, nil } var res Result + var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(respBody, &res); err != nil { logPrint(err) - return false,nil + return false, nil } if res.Success { dataBytes, _ := json.Marshal(res.Data) - if err = json.Unmarshal(dataBytes, &list);err !=nil { - return false,nil + var json = jsoniter.ConfigCompatibleWithStandardLibrary + if err = json.Unmarshal(dataBytes, &list); err != nil { + return false, nil } return true, list } return false, nil -} \ No newline at end of file +} -- Gitblit v1.8.0