商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.7 KiB

  1. // Code generated by protoc-gen-go.
  2. // source: product.proto
  3. // DO NOT EDIT!
  4. /*
  5. Package productrpc is a generated protocol buffer package.
  6. It is generated from these files:
  7. product.proto
  8. It has these top-level messages:
  9. GetRequest
  10. GetUuidRequest
  11. GetResponse
  12. */
  13. package productrpc
  14. import proto "github.com/chai2010/protorpc/proto"
  15. import math "math"
  16. import "io"
  17. import "log"
  18. import "net"
  19. import "net/rpc"
  20. import "time"
  21. import protorpc "github.com/chai2010/protorpc"
  22. // Reference imports to suppress errors if they are not otherwise used.
  23. var _ = proto.Marshal
  24. var _ = math.Inf
  25. // 使用key查询
  26. type GetRequest struct {
  27. Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"`
  28. Id *string `protobuf:"bytes,2,opt,name=id" json:"id,omitempty"`
  29. XXX_unrecognized []byte `json:"-"`
  30. }
  31. func (m *GetRequest) Reset() { *m = GetRequest{} }
  32. func (m *GetRequest) String() string { return proto.CompactTextString(m) }
  33. func (*GetRequest) ProtoMessage() {}
  34. func (m *GetRequest) GetDbname() string {
  35. if m != nil && m.Dbname != nil {
  36. return *m.Dbname
  37. }
  38. return ""
  39. }
  40. func (m *GetRequest) GetId() string {
  41. if m != nil && m.Id != nil {
  42. return *m.Id
  43. }
  44. return ""
  45. }
  46. type GetUuidRequest struct {
  47. Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"`
  48. Uuid *string `protobuf:"bytes,2,opt,name=uuid" json:"uuid,omitempty"`
  49. XXX_unrecognized []byte `json:"-"`
  50. }
  51. func (m *GetUuidRequest) Reset() { *m = GetUuidRequest{} }
  52. func (m *GetUuidRequest) String() string { return proto.CompactTextString(m) }
  53. func (*GetUuidRequest) ProtoMessage() {}
  54. func (m *GetUuidRequest) GetDbname() string {
  55. if m != nil && m.Dbname != nil {
  56. return *m.Dbname
  57. }
  58. return ""
  59. }
  60. func (m *GetUuidRequest) GetUuid() string {
  61. if m != nil && m.Uuid != nil {
  62. return *m.Uuid
  63. }
  64. return ""
  65. }
  66. // 使用key查询响应结构
  67. type GetResponse struct {
  68. Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
  69. XXX_unrecognized []byte `json:"-"`
  70. }
  71. func (m *GetResponse) Reset() { *m = GetResponse{} }
  72. func (m *GetResponse) String() string { return proto.CompactTextString(m) }
  73. func (*GetResponse) ProtoMessage() {}
  74. func (m *GetResponse) GetValue() []byte {
  75. if m != nil {
  76. return m.Value
  77. }
  78. return nil
  79. }
  80. func init() {
  81. }
  82. type ProductService interface {
  83. Get(in *GetRequest, out *GetResponse) error
  84. GetByUuid(in *GetUuidRequest, out *GetResponse) error
  85. GetSku(in *GetRequest, out *GetResponse) error
  86. GetSkuByUuid(in *GetUuidRequest, out *GetResponse) error
  87. }
  88. // AcceptProductServiceClient accepts connections on the listener and serves requests
  89. // for each incoming connection. Accept blocks; the caller typically
  90. // invokes it in a go statement.
  91. func AcceptProductServiceClient(lis net.Listener, x ProductService) {
  92. srv := rpc.NewServer()
  93. if err := srv.RegisterName("ProductService", x); err != nil {
  94. log.Fatal(err)
  95. }
  96. for {
  97. conn, err := lis.Accept()
  98. if err != nil {
  99. log.Fatalf("lis.Accept(): %v\n", err)
  100. }
  101. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  102. }
  103. }
  104. // RegisterProductService publish the given ProductService implementation on the server.
  105. func RegisterProductService(srv *rpc.Server, x ProductService) error {
  106. if err := srv.RegisterName("ProductService", x); err != nil {
  107. return err
  108. }
  109. return nil
  110. }
  111. // NewProductServiceServer returns a new ProductService Server.
  112. func NewProductServiceServer(x ProductService) *rpc.Server {
  113. srv := rpc.NewServer()
  114. if err := srv.RegisterName("ProductService", x); err != nil {
  115. log.Fatal(err)
  116. }
  117. return srv
  118. }
  119. // ListenAndServeProductService listen announces on the local network address laddr
  120. // and serves the given ProductService implementation.
  121. func ListenAndServeProductService(network, addr string, x ProductService) error {
  122. lis, err := net.Listen(network, addr)
  123. if err != nil {
  124. return err
  125. }
  126. defer lis.Close()
  127. srv := rpc.NewServer()
  128. if err := srv.RegisterName("ProductService", x); err != nil {
  129. return err
  130. }
  131. for {
  132. conn, err := lis.Accept()
  133. if err != nil {
  134. log.Fatalf("lis.Accept(): %v\n", err)
  135. }
  136. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  137. }
  138. }
  139. type ProductServiceClient struct {
  140. *rpc.Client
  141. }
  142. // NewProductServiceClient returns a ProductService rpc.Client and stub to handle
  143. // requests to the set of ProductService at the other end of the connection.
  144. func NewProductServiceClient(conn io.ReadWriteCloser) (*ProductServiceClient, *rpc.Client) {
  145. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  146. return &ProductServiceClient{c}, c
  147. }
  148. func (c *ProductServiceClient) Get(in *GetRequest, out *GetResponse) error {
  149. return c.Call("ProductService.Get", in, out)
  150. }
  151. func (c *ProductServiceClient) GetByUuid(in *GetUuidRequest, out *GetResponse) error {
  152. return c.Call("ProductService.GetByUuid", in, out)
  153. }
  154. func (c *ProductServiceClient) GetSku(in *GetRequest, out *GetResponse) error {
  155. return c.Call("ProductService.GetSku", in, out)
  156. }
  157. func (c *ProductServiceClient) GetSkuByUuid(in *GetUuidRequest, out *GetResponse) error {
  158. return c.Call("ProductService.GetSkuByUuid", in, out)
  159. }
  160. // DialProductService connects to an ProductService at the specified network address.
  161. func DialProductService(network, addr string) (*ProductServiceClient, *rpc.Client, error) {
  162. c, err := protorpc.Dial(network, addr)
  163. if err != nil {
  164. return nil, nil, err
  165. }
  166. return &ProductServiceClient{c}, c, nil
  167. }
  168. // DialProductServiceTimeout connects to an ProductService at the specified network address.
  169. func DialProductServiceTimeout(network, addr string,
  170. timeout time.Duration) (*ProductServiceClient, *rpc.Client, error) {
  171. c, err := protorpc.DialTimeout(network, addr, timeout)
  172. if err != nil {
  173. return nil, nil, err
  174. }
  175. return &ProductServiceClient{c}, c, nil
  176. }