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

183 lines
4.9 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. Id *string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
  28. XXX_unrecognized []byte `json:"-"`
  29. }
  30. func (m *GetRequest) Reset() { *m = GetRequest{} }
  31. func (m *GetRequest) String() string { return proto.CompactTextString(m) }
  32. func (*GetRequest) ProtoMessage() {}
  33. func (m *GetRequest) GetId() string {
  34. if m != nil && m.Id != nil {
  35. return *m.Id
  36. }
  37. return ""
  38. }
  39. type GetUuidRequest struct {
  40. Uuid *string `protobuf:"bytes,1,opt,name=uuid" json:"uuid,omitempty"`
  41. XXX_unrecognized []byte `json:"-"`
  42. }
  43. func (m *GetUuidRequest) Reset() { *m = GetUuidRequest{} }
  44. func (m *GetUuidRequest) String() string { return proto.CompactTextString(m) }
  45. func (*GetUuidRequest) ProtoMessage() {}
  46. func (m *GetUuidRequest) GetUuid() string {
  47. if m != nil && m.Uuid != nil {
  48. return *m.Uuid
  49. }
  50. return ""
  51. }
  52. // 使用key查询响应结构
  53. type GetResponse struct {
  54. Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
  55. XXX_unrecognized []byte `json:"-"`
  56. }
  57. func (m *GetResponse) Reset() { *m = GetResponse{} }
  58. func (m *GetResponse) String() string { return proto.CompactTextString(m) }
  59. func (*GetResponse) ProtoMessage() {}
  60. func (m *GetResponse) GetValue() []byte {
  61. if m != nil {
  62. return m.Value
  63. }
  64. return nil
  65. }
  66. func init() {
  67. }
  68. type ProductService interface {
  69. Get(in *GetRequest, out *GetResponse) error
  70. GetByUuid(in *GetUuidRequest, out *GetResponse) error
  71. }
  72. // AcceptProductServiceClient accepts connections on the listener and serves requests
  73. // for each incoming connection. Accept blocks; the caller typically
  74. // invokes it in a go statement.
  75. func AcceptProductServiceClient(lis net.Listener, x ProductService) {
  76. srv := rpc.NewServer()
  77. if err := srv.RegisterName("ProductService", x); err != nil {
  78. log.Fatal(err)
  79. }
  80. for {
  81. conn, err := lis.Accept()
  82. if err != nil {
  83. log.Fatalf("lis.Accept(): %v\n", err)
  84. }
  85. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  86. }
  87. }
  88. // RegisterProductService publish the given ProductService implementation on the server.
  89. func RegisterProductService(srv *rpc.Server, x ProductService) error {
  90. if err := srv.RegisterName("ProductService", x); err != nil {
  91. return err
  92. }
  93. return nil
  94. }
  95. // NewProductServiceServer returns a new ProductService Server.
  96. func NewProductServiceServer(x ProductService) *rpc.Server {
  97. srv := rpc.NewServer()
  98. if err := srv.RegisterName("ProductService", x); err != nil {
  99. log.Fatal(err)
  100. }
  101. return srv
  102. }
  103. // ListenAndServeProductService listen announces on the local network address laddr
  104. // and serves the given ProductService implementation.
  105. func ListenAndServeProductService(network, addr string, x ProductService) error {
  106. lis, err := net.Listen(network, addr)
  107. if err != nil {
  108. return err
  109. }
  110. defer lis.Close()
  111. srv := rpc.NewServer()
  112. if err := srv.RegisterName("ProductService", x); err != nil {
  113. return err
  114. }
  115. for {
  116. conn, err := lis.Accept()
  117. if err != nil {
  118. log.Fatalf("lis.Accept(): %v\n", err)
  119. }
  120. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  121. }
  122. }
  123. type ProductServiceClient struct {
  124. *rpc.Client
  125. }
  126. // NewProductServiceClient returns a ProductService rpc.Client and stub to handle
  127. // requests to the set of ProductService at the other end of the connection.
  128. func NewProductServiceClient(conn io.ReadWriteCloser) (*ProductServiceClient, *rpc.Client) {
  129. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  130. return &ProductServiceClient{c}, c
  131. }
  132. func (c *ProductServiceClient) Get(in *GetRequest, out *GetResponse) error {
  133. return c.Call("ProductService.Get", in, out)
  134. }
  135. func (c *ProductServiceClient) GetByUuid(in *GetUuidRequest, out *GetResponse) error {
  136. return c.Call("ProductService.GetByUuid", in, out)
  137. }
  138. // DialProductService connects to an ProductService at the specified network address.
  139. func DialProductService(network, addr string) (*ProductServiceClient, *rpc.Client, error) {
  140. c, err := protorpc.Dial(network, addr)
  141. if err != nil {
  142. return nil, nil, err
  143. }
  144. return &ProductServiceClient{c}, c, nil
  145. }
  146. // DialProductServiceTimeout connects to an ProductService at the specified network address.
  147. func DialProductServiceTimeout(network, addr string,
  148. timeout time.Duration) (*ProductServiceClient, *rpc.Client, error) {
  149. c, err := protorpc.DialTimeout(network, addr, timeout)
  150. if err != nil {
  151. return nil, nil, err
  152. }
  153. return &ProductServiceClient{c}, c, nil
  154. }