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

---
 userApi.go |   77 ++++++++++++++++++++------------------
 1 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/userApi.go b/userApi.go
index f2282ec..f0681e4 100644
--- a/userApi.go
+++ b/userApi.go
@@ -1,102 +1,106 @@
 package bhomedbapi
 
 import (
-	json "github.com/json-iterator/go"
+	jsoniter "github.com/json-iterator/go"
 )
 
 type UserApi struct {
-
 }
 
-func (api UserApi) Login(username string,password string) (bool,interface{}){
+func (api UserApi) Login(username string, password string) (bool, interface{}) {
 	url := "/data/api-u/sys/login"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
-	paramBody :=make(map[string]interface{},0)
-	paramBody["username"]=username
-	paramBody["password"]=password
-	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody,nil, nil)
+	paramBody := make(map[string]interface{}, 0)
+	paramBody["username"] = username
+	paramBody["password"] = password
+	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api UserApi) FindAllUser(curUserId string) (bool,interface{}) {
+func (api UserApi) FindAllUser(curUserId string) (bool, interface{}) {
 	url := "/data/api-u/users/findAllUser"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
-	query := map[string]string {
+	query := map[string]string{
 		"userId": curUserId,
 	}
 	body, err := client.DoGetRequest(url, query, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return true,res.Data
+	return true, res.Data
 }
 
-func (api UserApi) FindById(userId string) (bool,interface{}) {
+func (api UserApi) FindById(userId string) (bool, interface{}) {
 	url := "/data/api-u/users/findById"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
 	paramBody := map[string]interface{}{
 		"userId": userId,
 	}
-	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody,nil, nil)
+	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api UserApi) GetUserProfile(userId string) (bool,interface{}) {
+func (api UserApi) GetUserProfile(userId string) (bool, interface{}) {
 	url := "/data/api-u/users/profile"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
-	header := map[string]string {
+	header := map[string]string{
 		"Login_user_id": userId,
 	}
 	respBody, err := client.DoGetRequest(url, nil, header)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api UserApi) SaveAuth(paramBody map[string]interface{}) (bool,interface{}) {
+func (api UserApi) SaveAuth(paramBody map[string]interface{}) (bool, interface{}) {
 	url := "/data/api-u/users/saveAuth"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
-	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody,nil, nil)
+	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api UserApi) UpdatePwd(userId string, oldPwd string, newPwd string) (bool,interface{}) {
+func (api UserApi) UpdatePwd(userId string, oldPwd string, newPwd string) (bool, interface{}) {
 	url := "/data/api-u/users/updatePwd"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
 	client := NewClient(WithNodes(netNode))
@@ -105,13 +109,14 @@
 		"oldPwd": oldPwd,
 		"newPwd": newPwd,
 	}
-	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody,nil, nil)
+	respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
-	return res.Success,res.Data
-}
\ No newline at end of file
+	return res.Success, res.Data
+}

--
Gitblit v1.8.0