Browse Source

查询方法增加查询字段

master v0.4.1
guzeng 3 years ago
parent
commit
7077ff0fff
3 changed files with 55 additions and 4 deletions
  1. +46
    -2
      client.info.go
  2. +2
    -2
      client.info_test.go
  3. +7
    -0
      variable.go

+ 46
- 2
client.info.go View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
) )
func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
func Get(site_id, dbname, id string, field string, url ...string) (map[string]string, error) {
if dbname == "" || id == "" { if dbname == "" || id == "" {
return nil, errors.New("参数错误") return nil, errors.New("参数错误")
@ -17,7 +17,7 @@ func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
} }
defer conn.Close() defer conn.Close()
arg := GetParam{site_id, dbname, id}
arg := ReqParam{site_id, dbname, id, field}
req, err := SetReqData(arg) req, err := SetReqData(arg)
if err != nil { if err != nil {
@ -48,3 +48,47 @@ func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
return res_arr, nil return res_arr, nil
} }
func Get380Star(site_id, dbname string, field string, url ...string) (map[string]string, error) {
if dbname == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := ReqParam{site_id, dbname, "", field}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.Get380Star(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetResData(res)
if err != nil {
return nil, err
}
if res_data_de == "" {
return nil, nil
}
var res_arr map[string]string
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return res_arr, nil
}

+ 2
- 2
client.info_test.go View File

@ -7,9 +7,9 @@ import (
func Test_Get(t *testing.T) { func Test_Get(t *testing.T) {
siteid := "1056475" siteid := "1056475"
dbname := "shop_v2" dbname := "shop_v2"
key := "2"
key := "*"
res, err := Get(siteid, dbname, key)
res, err := Get380Star(siteid, dbname, key)
t.Log(res) t.Log(res)
t.Log(err) t.Log(err)


+ 7
- 0
variable.go View File

@ -17,3 +17,10 @@ type BoolRet struct {
Value bool `json:"value"` Value bool `json:"value"`
Msg string `json:"msg"` Msg string `json:"msg"`
} }
type ReqParam struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Id string `json:"id"`
Field string `json:"field"`
}

Loading…
Cancel
Save