22 Commits

19 changed files with 792 additions and 83 deletions
Split View
  1. +182
    -0
      client.all.go
  2. +13
    -0
      client.all_test.go
  3. +1
    -1
      client.balance.go
  4. +18
    -52
      client.go
  5. +92
    -0
      client.siteinfo.go
  6. +15
    -0
      client.siteinfo_test.go
  7. +62
    -0
      client.sitelist.go
  8. +13
    -0
      client.sitelist_test.go
  9. +7
    -3
      client_test.go
  10. +57
    -0
      code_bank.go
  11. +9
    -0
      code_bank_test.go
  12. +26
    -0
      common.go
  13. +106
    -0
      data.go
  14. +12
    -0
      go.mod
  15. +33
    -0
      go.sum
  16. +77
    -0
      sign.go
  17. +42
    -22
      site.pb.go
  18. +10
    -5
      site.proto
  19. +17
    -0
      valiable.go

+ 182
- 0
client.all.go View File

@ -0,0 +1,182 @@
package siterpc
import (
"encoding/json"
"errors"
"log"
"reflect"
"git.tetele.net/tgo/helper"
)
/**
* 取所有配置
* 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
}
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
}
/**
* 分组下所有配置
* 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
}
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
}

+ 13
- 0
client.all_test.go View File

@ -0,0 +1,13 @@
package siterpc
import (
"testing"
)
func Test_GetAllConfig(t *testing.T) {
list, err := GetGroupConfig("1056475", "shop_v2", "basic")
t.Log(list)
t.Log(err)
}

+ 1
- 1
client.balance.go View File

@ -1,4 +1,4 @@
package site
package siterpc
// import (
// "encoding/json"


+ 18
- 52
client.go View File

@ -1,12 +1,9 @@
package site
package siterpc
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"strconv"
"strings"
"time"
"git.tetele.net/tgo/crypter"
@ -14,17 +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
}
/**
* 由配置key取对应value
* 请求及回均加密验签
@ -32,12 +18,22 @@ type SiteConfigItemRes struct {
* GZ
*/
func GetConfigItem(site_id, dbname, key string, url ...string) (*SiteConfigItemRes, error) {
var site_rpc_url string = "127.0.0.1:7971"
if len(url) > 0 && url[0] != "" {
site_rpc_url = url[0]
ret, err := getconfig(site_id, dbname, key, url...)
if err != nil {
return ret, err
}
if ret.Exist == false {
return ret, errors.New("no data")
}
conn, _, err := DialSiteService("tcp", site_rpc_url)
return ret, err
}
func GetConfig(site_id, dbname, key string, url ...string) (*SiteConfigItemRes, error) {
return getconfig(site_id, dbname, key, url...)
}
func getconfig(site_id, dbname, key string, url ...string) (*SiteConfigItemRes, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
@ -57,9 +53,9 @@ func GetConfigItem(site_id, dbname, key string, url ...string) (*SiteConfigItemR
sign := Sign(encryData, now)
req := &ConfigRequest{proto.String(encryData), proto.String(now), proto.String(sign), nil}
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
res := &ConfigResponse{}
res := &Response{}
err = conn.GetConfig(req, res)
@ -103,33 +99,3 @@ func GetConfigItem(site_id, dbname, key string, url ...string) (*SiteConfigItemR
return nil, nil
}
/**
* 签名
*/
func Sign(data string, salt string) string {
var build strings.Builder
build.WriteString(data)
build.WriteString(salt)
build.WriteString("site55sign33")
data_str := build.String()
h := md5.New()
h.Write([]byte(data_str)) // 需要加密的字符串
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果
}
/**
* 验证签名
*/
func CheckSign(sign_str, data, salt string) bool {
sign := Sign(data, salt)
if strings.Compare(sign_str, sign) > -1 {
return true
}
return false
}

+ 92
- 0
client.siteinfo.go View File

@ -0,0 +1,92 @@
package siterpc
import (
"encoding/json"
"strconv"
"time"
"git.tetele.net/tgo/conf"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
type SiteInfoReq struct {
Master string
Host string
}
type SiteInfoRes struct {
SiteId string `json:"site_id"`
Dbname string `json:"database"`
Domainname string `json:"domainname"`
}
/**
* 由host取对应站点关键信息
* 请求及回均加密验签
* 2021/06/24
* GZ
*/
func GetSiteInfoByHost(host string, params ...string) (*SiteInfoRes, error) {
var res_arr SiteInfoRes
if conf.IS_PRIVATE {
res_arr.Dbname = conf.DBNAME
res_arr.SiteId = conf.SITE_ID
res_arr.Domainname = conf.DOMAIN
return &res_arr, nil
}
var url string = ""
var master string = ""
if len(params) > 1 {
master = params[1]
}
if len(params) > 0 {
url = params[0]
}
conn, err := rpc_server_conn(url)
if err != nil {
return nil, err
}
defer conn.Close()
arg := SiteInfoReq{master, host}
data_json, err := json.Marshal(arg)
if err != nil {
return nil, err
}
now_int64 := time.Now().Unix()
encryData := crypter.DesEn(string(data_json), DES_KEY)
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
res := &Response{}
err = conn.GetSiteInfoByHost(req, res)
if err != nil {
return nil, err
}
res_data, err := GetOrgData(res)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(res_data), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}

+ 15
- 0
client.siteinfo_test.go View File

@ -0,0 +1,15 @@
package siterpc
import (
"testing"
"git.tetele.net/tgo/conf"
)
func Test_GetSiteInfoByHost(t *testing.T) {
conf.IS_PRIVATE = true
res, err := GetSiteInfoByHost("dev.tetele.net")
t.Log(res)
t.Log(err)
}

+ 62
- 0
client.sitelist.go View File

@ -0,0 +1,62 @@
package siterpc
import (
"encoding/json"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
/**
* 由配置key取对应value
* 请求及回均加密验签
* 2021/01/20
* GZ
*/
func GetAllSite(url ...string) ([]map[string]string, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
now_int64 := time.Now().Unix()
encryData := crypter.DesEn("get_from_cache", DES_KEY)
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
res := &Response{}
err = conn.GetAllSite(req, res)
if err != nil {
return nil, err
}
res_data, err := GetOrgData(res)
if err != nil {
return []map[string]string{}, err
}
var res_arr []map[string]string
err = json.Unmarshal([]byte(res_data), &res_arr)
if err != nil {
return []map[string]string{}, err
}
return res_arr, nil
}

+ 13
- 0
client.sitelist_test.go View File

@ -0,0 +1,13 @@
package siterpc
import (
"testing"
)
func Test_GetAllSite(t *testing.T) {
res, err := GetAllSite()
t.Log(res)
t.Log(err)
}

+ 7
- 3
client_test.go View File

@ -1,15 +1,19 @@
package site
package siterpc
import (
"testing"
)
func Test_GetConfigItem(t *testing.T) {
siteid := "100065"
siteid := "1056475"
dbname := "test1_tetele_com"
key := "percentage"
key := "site_secret"
res, err := GetConfigItem(siteid, dbname, key)
t.Log(res)
t.Log(err)
res, err = GetConfig(siteid, dbname, key)
t.Log(res)
t.Log(err)
}

+ 57
- 0
code_bank.go View File

@ -0,0 +1,57 @@
package siterpc
import (
"encoding/json"
"errors"
)
/**
* 获取code_bank一条可用记录
* 2021/09/09
* linsen
*/
func GetOneCode(site_id, dbname string, url ...string) (string, error) {
if dbname == "" {
return "", errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
}
defer conn.Close()
arg := SiteConfigItemReqArg{site_id, dbname, ""}
req, err := SetReqData(arg)
if err != nil {
return "", err
}
res := &Response{}
err = conn.GetOneCode(req, res)
if err != nil {
return "", err
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
}
var bankCode string
err = json.Unmarshal([]byte(res_data_de),&bankCode)
if err != nil {
return "", err
}
if res_data_de == "" {
return "", nil
}
return bankCode, nil
}

+ 9
- 0
code_bank_test.go View File

@ -0,0 +1,9 @@
package siterpc
import "testing"
func Test_getcode(t *testing.T){
res,err := GetOneCode("1058278","shop_v2")
t.Log(res)
t.Log(err)
}

+ 26
- 0
common.go View File

@ -0,0 +1,26 @@
package siterpc
import (
"git.tetele.net/tgo/conf"
)
var DES_KEY = "confdata"
func rpc_server_conn(url ...string) (*SiteServiceClient, error) {
var rpc_url string
if len(url) > 0 && url[0] != "" {
rpc_url = url[0]
} else if conf.SITE_RPC_URL != "" {
rpc_url = conf.SITE_RPC_URL
} else {
rpc_url = "127.0.0.1:" + conf.SITE_RPC_PORT
}
conn, _, err := DialSiteService("tcp", rpc_url)
if err != nil {
return nil, err
}
return conn, nil
}

+ 106
- 0
data.go View File

@ -0,0 +1,106 @@
package siterpc
import (
"encoding/json"
"errors"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
func SetResData(data interface{}, res *Response) {
res_data_json, err := json.Marshal(data)
if err == nil {
encryData := crypter.DesEn(string(res_data_json), DES_KEY)
now_str := strconv.FormatInt(time.Now().Unix(), 10)
res_sign := Sign(encryData, now_str)
res.Data = proto.String(encryData)
res.Time = proto.String(now_str)
res.Sign = proto.String(res_sign)
}
}
func SetReqData(arg interface{}) (*Request, error) {
data_json, err := json.Marshal(arg)
if err != nil {
return nil, err
}
now_int64 := time.Now().Unix()
encryData := crypter.DesEn(string(data_json), DES_KEY)
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
return &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}, nil
}
func GetReqData(req *Request) (string, error) {
res_data := req.GetData()
if res_data != "" {
time_int64, err := strconv.ParseInt(req.GetTime(), 10, 64)
if err != nil {
return "", err
}
now_int64 := time.Now().Unix()
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 {
//时间误差前后10秒,返回
return "", errors.New("返回时间错误")
}
check_sign := CheckSign(req.GetSign(), res_data, req.GetTime())
if !check_sign {
return "", errors.New("返回数据签名错误")
}
//解密
return crypter.DesDe(res_data, DES_KEY), nil
}
return "", nil
}
func GetResData(res *Response) (string, error) {
res_data := res.GetData()
if res_data != "" {
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64)
if err != nil {
return "", err
}
now_int64 := time.Now().Unix()
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 {
//时间误差前后10秒,返回
return "", errors.New("返回时间错误")
}
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime())
if !check_sign {
return "", errors.New("返回数据签名错误")
}
//解密
return crypter.DesDe(res_data, DES_KEY), nil
}
return "", nil
}

+ 12
- 0
go.mod View File

@ -0,0 +1,12 @@
module git.tetele.net/tgo/siterpc
go 1.14
require (
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.1.3
github.com/golang/protobuf v1.5.2
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
)

+ 33
- 0
go.sum View File

@ -0,0 +1,33 @@
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/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo=
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/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54=
github.com/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w=
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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/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=
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/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=

+ 77
- 0
sign.go View File

@ -0,0 +1,77 @@
package siterpc
import (
"crypto/md5"
"encoding/hex"
"errors"
"strconv"
"strings"
"time"
"git.tetele.net/tgo/crypter"
)
/**
* 签名
*/
func Sign(data string, salt string) string {
var build strings.Builder
build.WriteString(data)
build.WriteString(salt)
build.WriteString("site55sign33")
data_str := build.String()
h := md5.New()
h.Write([]byte(data_str)) // 需要加密的字符串
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果
}
/**
* 验证签名
*/
func CheckSign(sign_str, data, salt string) bool {
sign := Sign(data, salt)
if strings.Compare(sign_str, sign) > -1 {
return true
}
return false
}
/**
* 解密
*/
func GetOrgData(res *Response) (string, error) {
res_data := res.GetData()
if res_data == "" {
return "", errors.New("未收到收据")
}
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64)
if err != nil {
return "", err
}
now_int64 := time.Now().Unix()
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 {
//时间误差前后10秒,返回
return "", errors.New("返回时间错误")
}
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime())
if !check_sign {
return "", errors.New("返回数据签名错误")
}
//解密
res_data_de := crypter.DesDe(res_data, DES_KEY)
return res_data_de, nil
}

+ 42
- 22
site.pb.go View File

@ -3,16 +3,16 @@
// DO NOT EDIT!
/*
Package site is a generated protocol buffer package.
Package siterpc is a generated protocol buffer package.
It is generated from these files:
site.proto
It has these top-level messages:
ConfigRequest
ConfigResponse
Request
Response
*/
package site
package siterpc
import proto "github.com/chai2010/protorpc/proto"
import math "math"
@ -29,32 +29,32 @@ var _ = proto.Marshal
var _ = math.Inf
// 配置信息请求结构
type ConfigRequest struct {
type Request struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *ConfigRequest) Reset() { *m = ConfigRequest{} }
func (m *ConfigRequest) String() string { return proto.CompactTextString(m) }
func (*ConfigRequest) ProtoMessage() {}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (m *ConfigRequest) GetData() string {
func (m *Request) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *ConfigRequest) GetTime() string {
func (m *Request) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *ConfigRequest) GetSign() string {
func (m *Request) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
@ -62,32 +62,32 @@ func (m *ConfigRequest) GetSign() string {
}
// 配置信息响应结构
type ConfigResponse struct {
type Response struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *ConfigResponse) Reset() { *m = ConfigResponse{} }
func (m *ConfigResponse) String() string { return proto.CompactTextString(m) }
func (*ConfigResponse) ProtoMessage() {}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (m *ConfigResponse) GetData() string {
func (m *Response) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *ConfigResponse) GetTime() string {
func (m *Response) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *ConfigResponse) GetSign() string {
func (m *Response) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
@ -98,8 +98,13 @@ func init() {
}
type SiteService interface {
GetConfig(in *ConfigRequest, out *ConfigResponse) error
GetBalanceType(in *ConfigRequest, out *ConfigResponse) error
GetConfig(in *Request, out *Response) error
GetBalanceType(in *Request, out *Response) error
GetAllSite(in *Request, out *Response) error
GetSiteInfoByHost(in *Request, out *Response) error
GetAllConfig(in *Request, out *Response) error
GetGroupConfig(in *Request, out *Response) error
GetOneCode(in *Request, out *Response) error
}
// AcceptSiteServiceClient accepts connections on the listener and serves requests
@ -171,12 +176,27 @@ func NewSiteServiceClient(conn io.ReadWriteCloser) (*SiteServiceClient, *rpc.Cli
return &SiteServiceClient{c}, c
}
func (c *SiteServiceClient) GetConfig(in *ConfigRequest, out *ConfigResponse) error {
func (c *SiteServiceClient) GetConfig(in *Request, out *Response) error {
return c.Call("SiteService.GetConfig", in, out)
}
func (c *SiteServiceClient) GetBalanceType(in *ConfigRequest, out *ConfigResponse) error {
func (c *SiteServiceClient) GetBalanceType(in *Request, out *Response) error {
return c.Call("SiteService.GetBalanceType", in, out)
}
func (c *SiteServiceClient) GetAllSite(in *Request, out *Response) error {
return c.Call("SiteService.GetAllSite", in, out)
}
func (c *SiteServiceClient) GetSiteInfoByHost(in *Request, out *Response) error {
return c.Call("SiteService.GetSiteInfoByHost", in, out)
}
func (c *SiteServiceClient) GetAllConfig(in *Request, out *Response) error {
return c.Call("SiteService.GetAllConfig", in, out)
}
func (c *SiteServiceClient) GetGroupConfig(in *Request, out *Response) error {
return c.Call("SiteService.GetGroupConfig", in, out)
}
func (c *SiteServiceClient) GetOneCode(in *Request, out *Response) error {
return c.Call("SiteService.GetOneCode", in, out)
}
// DialSiteService connects to an SiteService at the specified network address.
func DialSiteService(network, addr string) (*SiteServiceClient, *rpc.Client, error) {


+ 10
- 5
site.proto View File

@ -1,15 +1,15 @@
syntax = "proto3";
package site;
package siterpc;
//
message ConfigRequest {
message Request {
string data = 1;
string time = 2;
string sign = 3;
}
//
message ConfigResponse {
message Response {
string data = 1;
string time = 2;
string sign = 3;
@ -18,6 +18,11 @@ message ConfigResponse {
// rpc方法
service SiteService {
rpc getConfig (ConfigRequest) returns (ConfigResponse); //
rpc getBalanceType (ConfigRequest) returns (ConfigResponse); //
rpc getConfig (Request) returns (Response); //
rpc getBalanceType (Request) returns (Response); //
rpc getAllSite(Request) returns (Response);//
rpc getSiteInfoByHost(Request) returns (Response);//host获取站点关键信息
rpc getAllConfig (Request) returns (Response); //
rpc getGroupConfig (Request) returns (Response); //
rpc getOneCode (Request) returns (Response); // code_bank未使用的一条code
}

+ 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