Browse Source

增加获取所有配置方法

master v0.7.2
guzeng 3 years ago
parent
commit
8d6f89b962
4 changed files with 134 additions and 12 deletions
  1. +104
    -0
      client.all.go
  2. +13
    -0
      client.all_test.go
  3. +0
    -12
      client.go
  4. +17
    -0
      valiable.go

+ 104
- 0
client.all.go View File

@ -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
}

+ 13
- 0
client.all_test.go View File

@ -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)
}

+ 0
- 12
client.go View File

@ -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
* 请求及回均加密验签


+ 17
- 0
valiable.go View File

@ -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
}

Loading…
Cancel
Save