package bhomedbapi import ( "encoding/json" ) type UserApi struct { } func (api UserApi) Login(username string,password string) (bool,interface{}){ url := DATA_URL_PREFIX + "/user/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_JSON, paramBody,nil, nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(respBody, &res); err != nil { return false,nil } return res.Success,res.Data } func (api UserApi) FindAllUser(curUserId string) (bool,interface{}) { url := DATA_URL_PREFIX + "/user/findAllUser" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) query := map[string]string { "userId": curUserId, } body, err := client.DoGetRequest(url, query, nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(body, &res); err != nil { return false,nil } return true,res.Data } func (api UserApi) FindById(userId string) (bool,interface{}) { url := DATA_URL_PREFIX + "/user/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) if err != nil { return false,nil } var res Result if err = json.Unmarshal(respBody, &res); err != nil { return false,nil } return res.Success,res.Data } func (api UserApi) SaveAuth(paramBody map[string]interface{}) (bool,interface{}) { url := DATA_URL_PREFIX + "/user/saveAuth" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) respBody, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody,nil, nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(respBody, &res); err != nil { return false,nil } return res.Success,res.Data } func (api UserApi) UpdatePwd(userId string, oldPwd string, newPwd string) (bool,interface{}) { url := DATA_URL_PREFIX + "/user/updatePwd" netNode := getNetNode(url2Topic(Topic_System_Service, url)) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "userId": userId, "oldPwd": oldPwd, "newPwd": newPwd, } respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody,nil, nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(respBody, &res); err != nil { return false,nil } return res.Success,res.Data }