4 Commits

Author SHA1 Message Date
  guzeng 639c701dec 修改查询条件 3 years ago
  guzeng 7077ff0fff 查询方法增加查询字段 3 years ago
  guzeng 0cbfce0db4 增加Get380Star方法 3 years ago
  guzeng 1838e087aa 修改调用方法 3 years ago
8 changed files with 215 additions and 0 deletions
Unified View
  1. +94
    -0
      client.info.go
  2. +16
    -0
      client.info_test.go
  3. +50
    -0
      client.is_open.go
  4. +17
    -0
      client.is_open_test.go
  5. +25
    -0
      conn.go
  6. +4
    -0
      supplier.pb.go
  7. +1
    -0
      supplier.proto
  8. +8
    -0
      variable.go

+ 94
- 0
client.info.go View File

@ -0,0 +1,94 @@
package supplierrpc
import (
"encoding/json"
"errors"
)
func Get(site_id, dbname, id string, field string, url ...string) (map[string]string, error) {
if dbname == "" || id == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := ReqParam{site_id, dbname, id, field}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.Get(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
}
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
}

+ 16
- 0
client.info_test.go View File

@ -0,0 +1,16 @@
package supplierrpc
import (
"testing"
)
func Test_Get(t *testing.T) {
siteid := "1056475"
dbname := "shop_v2"
key := "*"
res, err := Get380Star(siteid, dbname, key)
t.Log(res)
t.Log(err)
}

+ 50
- 0
client.is_open.go View File

@ -0,0 +1,50 @@
package supplierrpc
import (
"encoding/json"
"errors"
)
func IsOpen(site_id, dbname, id string, url ...string) (*BoolRet, error) {
if dbname == "" || id == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
arg := GetParam{site_id, dbname, id}
req, err := SetReqData(arg)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.IsOpen(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 BoolRet
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}

+ 17
- 0
client.is_open_test.go View File

@ -0,0 +1,17 @@
package supplierrpc
import (
"testing"
)
func Test_IsOpen(t *testing.T) {
siteid := "1056475"
dbname := "shop_v2"
key := "1"
res, err := IsOpen(siteid, dbname, key)
t.Log(res)
t.Log(res.Value)
t.Log(err)
}

+ 25
- 0
conn.go View File

@ -0,0 +1,25 @@
package supplierrpc
import (
"git.tetele.net/tgo/conf"
)
func rpc_server_conn(url ...string) (*SupplierServiceClient, error) {
var rpc_url string
if len(url) > 0 && url[0] != "" {
rpc_url = url[0]
} else if conf.SUPPLIER_RPC_URL != "" {
rpc_url = conf.SUPPLIER_RPC_URL
} else {
rpc_url = "127.0.0.1:" + conf.SUPPLIER_RPC_PORT
}
conn, _, err := DialSupplierService("tcp", rpc_url)
if err != nil {
return nil, err
}
return conn, nil
}

+ 4
- 0
supplier.pb.go View File

@ -101,6 +101,7 @@ type SupplierService interface {
Get(in *Request, out *Response) error Get(in *Request, out *Response) error
GetByUuid(in *Request, out *Response) error GetByUuid(in *Request, out *Response) error
IsOpen(in *Request, out *Response) error IsOpen(in *Request, out *Response) error
Get380Star(in *Request, out *Response) error
} }
// AcceptSupplierServiceClient accepts connections on the listener and serves requests // AcceptSupplierServiceClient accepts connections on the listener and serves requests
@ -181,6 +182,9 @@ func (c *SupplierServiceClient) GetByUuid(in *Request, out *Response) error {
func (c *SupplierServiceClient) IsOpen(in *Request, out *Response) error { func (c *SupplierServiceClient) IsOpen(in *Request, out *Response) error {
return c.Call("SupplierService.IsOpen", in, out) return c.Call("SupplierService.IsOpen", in, out)
} }
func (c *SupplierServiceClient) Get380Star(in *Request, out *Response) error {
return c.Call("SupplierService.Get380Star", in, out)
}
// DialSupplierService connects to an SupplierService at the specified network address. // DialSupplierService connects to an SupplierService at the specified network address.
func DialSupplierService(network, addr string) (*SupplierServiceClient, *rpc.Client, error) { func DialSupplierService(network, addr string) (*SupplierServiceClient, *rpc.Client, error) {


+ 1
- 0
supplier.proto View File

@ -20,4 +20,5 @@ service SupplierService {
rpc Get (Request) returns (Response); // 使id查询 rpc Get (Request) returns (Response); // 使id查询
rpc GetByUuid (Request) returns (Response); // 使uuid查询 rpc GetByUuid (Request) returns (Response); // 使uuid查询
rpc IsOpen (Request) returns (Response); // rpc IsOpen (Request) returns (Response); //
rpc Get380Star (Request) returns (Response); // 380star供应商数据
} }

+ 8
- 0
variable.go View File

@ -12,8 +12,16 @@ type GetUuidParam struct {
SiteId string `json:"site_id"` SiteId string `json:"site_id"`
Dbname string `json:"database"` Dbname string `json:"database"`
Uuid string `json:"uuid"` Uuid string `json:"uuid"`
Field string `json:"field"`
} }
type BoolRet struct { 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