商品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.

199 lines
5.3 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. }
  86. // AcceptProductServiceClient accepts connections on the listener and serves requests
  87. // for each incoming connection. Accept blocks; the caller typically
  88. // invokes it in a go statement.
  89. func AcceptProductServiceClient(lis net.Listener, x ProductService) {
  90. srv := rpc.NewServer()
  91. if err := srv.RegisterName("ProductService", x); err != nil {
  92. log.Fatal(err)
  93. }
  94. for {
  95. conn, err := lis.Accept()
  96. if err != nil {
  97. log.Fatalf("lis.Accept(): %v\n", err)
  98. }
  99. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  100. }
  101. }
  102. // RegisterProductService publish the given ProductService implementation on the server.
  103. func RegisterProductService(srv *rpc.Server, x ProductService) error {
  104. if err := srv.RegisterName("ProductService", x); err != nil {
  105. return err
  106. }
  107. return nil
  108. }
  109. // NewProductServiceServer returns a new ProductService Server.
  110. func NewProductServiceServer(x ProductService) *rpc.Server {
  111. srv := rpc.NewServer()
  112. if err := srv.RegisterName("ProductService", x); err != nil {
  113. log.Fatal(err)
  114. }
  115. return srv
  116. }
  117. // ListenAndServeProductService listen announces on the local network address laddr
  118. // and serves the given ProductService implementation.
  119. func ListenAndServeProductService(network, addr string, x ProductService) error {
  120. lis, err := net.Listen(network, addr)
  121. if err != nil {
  122. return err
  123. }
  124. defer lis.Close()
  125. srv := rpc.NewServer()
  126. if err := srv.RegisterName("ProductService", x); err != nil {
  127. return err
  128. }
  129. for {
  130. conn, err := lis.Accept()
  131. if err != nil {
  132. log.Fatalf("lis.Accept(): %v\n", err)
  133. }
  134. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  135. }
  136. }
  137. type ProductServiceClient struct {
  138. *rpc.Client
  139. }
  140. // NewProductServiceClient returns a ProductService rpc.Client and stub to handle
  141. // requests to the set of ProductService at the other end of the connection.
  142. func NewProductServiceClient(conn io.ReadWriteCloser) (*ProductServiceClient, *rpc.Client) {
  143. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  144. return &ProductServiceClient{c}, c
  145. }
  146. func (c *ProductServiceClient) Get(in *GetRequest, out *GetResponse) error {
  147. return c.Call("ProductService.Get", in, out)
  148. }
  149. func (c *ProductServiceClient) GetByUuid(in *GetUuidRequest, out *GetResponse) error {
  150. return c.Call("ProductService.GetByUuid", in, out)
  151. }
  152. // DialProductService connects to an ProductService at the specified network address.
  153. func DialProductService(network, addr string) (*ProductServiceClient, *rpc.Client, error) {
  154. c, err := protorpc.Dial(network, addr)
  155. if err != nil {
  156. return nil, nil, err
  157. }
  158. return &ProductServiceClient{c}, c, nil
  159. }
  160. // DialProductServiceTimeout connects to an ProductService at the specified network address.
  161. func DialProductServiceTimeout(network, addr string,
  162. timeout time.Duration) (*ProductServiceClient, *rpc.Client, error) {
  163. c, err := protorpc.DialTimeout(network, addr, timeout)
  164. if err != nil {
  165. return nil, nil, err
  166. }
  167. return &ProductServiceClient{c}, c, nil
  168. }