From 8d6f89b96201e5381531bf0c41ddb2bfed5db72d Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 4 Sep 2021 17:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E9=85=8D=E7=BD=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.all.go | 104 +++++++++++++++++++++++++++++++++++++++++++++ client.all_test.go | 13 ++++++ client.go | 12 ------ valiable.go | 17 ++++++++ 4 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 client.all.go create mode 100644 client.all_test.go create mode 100644 valiable.go diff --git a/client.all.go b/client.all.go new file mode 100644 index 0000000..442f855 --- /dev/null +++ b/client.all.go @@ -0,0 +1,104 @@ +package siterpc + +import ( + "encoding/json" + "errors" +) + +/** + * 取所有配置 + * 2021/09/04 + * GZ + */ +func GetAllConfig(site_id, dbname 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 := SiteConfigItemReqArg{site_id, dbname, ""} + + req, err := SetReqData(arg) + if err != nil { + return nil, err + } + res := &Response{} + + err = conn.GetAllConfig(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 + +} + +/** + * 分组下所有配置 + * 2021/09/04 + * GZ + */ +func GetGroupConfig(site_id, dbname string, groupname 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 := SiteConfigItemReqArg{site_id, dbname, groupname} + + req, err := SetReqData(arg) + if err != nil { + return nil, err + } + res := &Response{} + + err = conn.GetGroupConfig(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 + +} diff --git a/client.all_test.go b/client.all_test.go new file mode 100644 index 0000000..956c767 --- /dev/null +++ b/client.all_test.go @@ -0,0 +1,13 @@ +package siterpc + +import ( + "testing" +) + +func Test_GetGroupConfig(t *testing.T) { + + list, err := GetGroupConfig("1056475", "shop_v2", "basic") + + t.Log(list) + t.Log(err) +} diff --git a/client.go b/client.go index 461dcfe..fa3fed4 100644 --- a/client.go +++ b/client.go @@ -11,18 +11,6 @@ import ( "github.com/golang/protobuf/proto" ) -type SiteConfigItemReqArg struct { - SiteId string `json:"site_id"` - Dbname string `json:"dbname"` - Key string `json:"key"` -} - -type SiteConfigItemRes struct { - Type string - Value string - Exist bool -} - /** * 由配置key取对应value * 请求及回均加密验签 diff --git a/valiable.go b/valiable.go new file mode 100644 index 0000000..7e16d5d --- /dev/null +++ b/valiable.go @@ -0,0 +1,17 @@ +package siterpc + +type SiteConfigItemReqArg struct { + SiteId string `json:"site_id"` + Dbname string `json:"dbname"` + Key string `json:"key"` +} + +type SiteConfigItemRes struct { + Type string + Value string + Exist bool +} + +type ConfigListRes struct { + list string +}