| @ -0,0 +1,19 @@ | |||||
| package productrpc | |||||
| import ( | |||||
| "git.tetele.net/tgo/conf" | |||||
| ) | |||||
| func rpc_server_conn(url ...string) (*ProductServiceClient, error) { | |||||
| var rpc_url string = "127.0.0.1:" + conf.PRODUCT_RPC_PORT | |||||
| if len(url) > 0 && url[0] != "" { | |||||
| rpc_url = url[0] | |||||
| } | |||||
| conn, _, err := DialProductService("tcp", rpc_url) | |||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| return conn, nil | |||||
| } | |||||
| @ -0,0 +1,41 @@ | |||||
| package productrpc | |||||
| import ( | |||||
| "encoding/json" | |||||
| // "strconv" | |||||
| // "time" | |||||
| "github.com/golang/protobuf/proto" | |||||
| ) | |||||
| /** | |||||
| * id获取商品信息 | |||||
| * 2021/08/20 | |||||
| * GZ | |||||
| */ | |||||
| func Get(dbname, id string, url ...string) (map[string]string, error) { | |||||
| conn, err := rpc_server_conn(url...) | |||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| defer conn.Close() | |||||
| req := &GetRequest{proto.String(dbname), proto.String(id), nil} | |||||
| res := &GetResponse{} | |||||
| err = conn.Get(req, res) | |||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| value := res.GetValue() | |||||
| var data map[string]string | |||||
| err = json.Unmarshal(value, &data) | |||||
| return data, err | |||||
| } | |||||
| @ -0,0 +1,15 @@ | |||||
| package productrpc | |||||
| import ( | |||||
| "testing" | |||||
| ) | |||||
| func Test_Get(t *testing.T) { | |||||
| dbname := "shop_v2" | |||||
| id := "1" | |||||
| ret, err := Get(dbname, id) | |||||
| t.Log(ret) | |||||
| t.Log(err) | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| module git.tetele.net/tgo/productrpc | |||||
| go 1.14 | |||||
| require ( | |||||
| git.tetele.net/tgo/conf v0.33.1 // indirect | |||||
| github.com/chai2010/protorpc v1.1.3 // indirect | |||||
| golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect | |||||
| ) | |||||
| @ -0,0 +1,10 @@ | |||||
| 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= | |||||
| 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 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= | |||||
| github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |||||
| github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= | |||||
| github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | |||||
| golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= | |||||
| golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |||||