Browse Source

修改取所有配置方法

master v0.7.3
guzeng 3 years ago
parent
commit
0df76c79ee
4 changed files with 91 additions and 9 deletions
  1. +82
    -4
      client.all.go
  2. +1
    -1
      client.all_test.go
  3. +5
    -4
      go.mod
  4. +3
    -0
      go.sum

+ 82
- 4
client.all.go View File

@ -3,6 +3,10 @@ package siterpc
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"log"
"reflect"
"git.tetele.net/tgo/helper"
) )
/** /**
@ -10,13 +14,14 @@ import (
* 2021/09/04 * 2021/09/04
* GZ * GZ
*/ */
func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, error) {
func GetAllConfig(site_id, dbname string, url ...string) (map[string]string, error) {
if dbname == "" { if dbname == "" {
return nil, errors.New("参数错误") return nil, errors.New("参数错误")
} }
conn, err := rpc_server_conn(url...) conn, err := rpc_server_conn(url...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -50,7 +55,43 @@ func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, e
if err != nil { if err != nil {
return nil, err return nil, err
} }
return res_arr, nil
var res_map map[string]string = make(map[string]string)
if len(res_arr) > 0 {
var value string
for _, info := range res_arr {
value = ""
switch info["Type"] {
case "select":
var content interface{}
err = json.Unmarshal([]byte(info["Content"]), &content)
if err != nil {
log.Println(err)
}
content_type := reflect.TypeOf(content).String() //数据字典的类型
switch content_type {
case "[]interface {}": //数组形式,value字段对应数组的key
list := content.([]interface{})
val_key := helper.ToInt(info["Value"])
value = helper.ToString(list[val_key])
case "map[string]interface {}": //map形式,value字段对应key
list := content.(map[string]interface{})
value = helper.ToString(list[info["Value"]])
}
default:
value = info["Value"]
}
res_map[info["Name"]] = value
}
}
return res_map, nil
} }
@ -59,7 +100,7 @@ func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, e
* 2021/09/04 * 2021/09/04
* GZ * GZ
*/ */
func GetGroupConfig(site_id, dbname string, groupname string, url ...string) ([]map[string]string, error) {
func GetGroupConfig(site_id, dbname string, groupname string, url ...string) (map[string]string, error) {
if dbname == "" { if dbname == "" {
return nil, errors.New("参数错误") return nil, errors.New("参数错误")
@ -99,6 +140,43 @@ func GetGroupConfig(site_id, dbname string, groupname string, url ...string) ([]
if err != nil { if err != nil {
return nil, err return nil, err
} }
return res_arr, nil
var res_map map[string]string = make(map[string]string)
if len(res_arr) > 0 {
var value string
for _, info := range res_arr {
value = ""
switch info["Type"] {
case "select":
var content interface{}
err = json.Unmarshal([]byte(info["Content"]), &content)
if err != nil {
log.Println(err)
}
content_type := reflect.TypeOf(content).String() //数据字典的类型
switch content_type {
case "[]interface {}": //数组形式,value字段对应数组的key
list := content.([]interface{})
val_key := helper.ToInt(info["Value"])
value = helper.ToString(list[val_key])
case "map[string]interface {}": //map形式,value字段对应key
list := content.(map[string]interface{})
value = helper.ToString(list[info["Value"]])
}
default:
value = info["Value"]
}
res_map[info["Name"]] = value
}
}
return res_map, nil
} }

+ 1
- 1
client.all_test.go View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
) )
func Test_GetGroupConfig(t *testing.T) {
func Test_GetAllConfig(t *testing.T) {
list, err := GetGroupConfig("1056475", "shop_v2", "basic") list, err := GetGroupConfig("1056475", "shop_v2", "basic")


+ 5
- 4
go.mod View File

@ -3,9 +3,10 @@ module git.tetele.net/tgo/siterpc
go 1.14 go 1.14
require ( require (
git.tetele.net/tgo/conf v0.33.1 // indirect
git.tetele.net/tgo/crypter v0.2.2 // indirect
github.com/chai2010/protorpc v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
git.tetele.net/tgo/conf v0.33.1
git.tetele.net/tgo/crypter v0.2.2
git.tetele.net/tgo/helper v0.1.8
github.com/chai2010/protorpc v1.0.0
github.com/golang/protobuf v1.5.2
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
) )

+ 3
- 0
go.sum View File

@ -2,6 +2,8 @@ git.tetele.net/tgo/conf v0.33.1 h1:ZEIv3Vq35RCv5f3T3Uz97s2mkZLl7W5OlmXvzI3/sS8=
git.tetele.net/tgo/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= git.tetele.net/tgo/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A=
git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo=
git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0=
git.tetele.net/tgo/helper v0.1.8 h1:6eeUYmO0Xv2n+HluHKAOm6y2CcLmr2QPnGxzHy3yyWc=
git.tetele.net/tgo/helper v0.1.8/go.mod h1:89mQwyfqZ+t8YXiVwzSxA70gLlUNqoZGDEUxvV46jXk=
github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo=
github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -20,6 +22,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=


Loading…
Cancel
Save