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 | 63 +++++++++++++++++++++---------- 1 files changed, 43 insertions(+), 20 deletions(-) diff --git a/dicApi.go b/dicApi.go index e56c940..0c977b6 100644 --- a/dicApi.go +++ b/dicApi.go @@ -1,51 +1,74 @@ -package dbapi +package bhomedbapi import ( - "encoding/json" + "basic.com/pubsub/protomsg.git" + 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)) - if netNode == nil { - return false,nil - } 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)) - if netNode == nil { - return false,nil - } 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 -} \ No newline at end of file + return res.Success, res.Data +} + +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 + } + var res Result + var json = jsoniter.ConfigCompatibleWithStandardLibrary + if err = json.Unmarshal(respBody, &res); err != nil { + logPrint(err) + return false, nil + } + if res.Success { + dataBytes, _ := json.Marshal(res.Data) + var json = jsoniter.ConfigCompatibleWithStandardLibrary + if err = json.Unmarshal(dataBytes, &list); err != nil { + return false, nil + } + return true, list + } + return false, nil +} -- Gitblit v1.8.0