Browse Source

定义接口

master v0.0.1
guzeng 2 years ago
parent
commit
fbf27a9067
4 changed files with 240 additions and 1 deletions
  1. +7
    -1
      README.md
  2. +3
    -0
      go.mod
  3. +206
    -0
      order.pb.go
  4. +24
    -0
      order.proto

+ 7
- 1
README.md View File

@ -1,3 +1,9 @@
# orderrpcv2
2.0订单rpc数据结构
2.0订单rpc
## 自动生成PB文件
~~~
protoc --go_out=./ order.proto
~~~

+ 3
- 0
go.mod View File

@ -0,0 +1,3 @@
module git.tetele.net/tgo/orderrpcv2
go 1.14

+ 206
- 0
order.pb.go View File

@ -0,0 +1,206 @@
// Code generated by protoc-gen-go.
// source: order.proto
// DO NOT EDIT!
/*
Package orderrpcv2 is a generated protocol buffer package.
It is generated from these files:
order.proto
It has these top-level messages:
Request
Response
*/
package orderrpcv2
import proto "github.com/chai2010/protorpc/proto"
import math "math"
import "io"
import "log"
import "net"
import "net/rpc"
import "time"
import protorpc "github.com/chai2010/protorpc"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = math.Inf
// 请求结构
type Request struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (m *Request) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *Request) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *Request) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
return ""
}
// 响应结构
type Response struct {
Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Time *string `protobuf:"bytes,2,opt,name=time" json:"time,omitempty"`
Sign *string `protobuf:"bytes,3,opt,name=sign" json:"sign,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (m *Response) GetData() string {
if m != nil && m.Data != nil {
return *m.Data
}
return ""
}
func (m *Response) GetTime() string {
if m != nil && m.Time != nil {
return *m.Time
}
return ""
}
func (m *Response) GetSign() string {
if m != nil && m.Sign != nil {
return *m.Sign
}
return ""
}
func init() {
}
type OrderService interface {
Create(in *Request, out *Response) error
CreateByCart(in *Request, out *Response) error
Cancel(in *Request, out *Response) error
AutoReceive(in *Request, out *Response) error
}
// AcceptOrderServiceClient accepts connections on the listener and serves requests
// for each incoming connection. Accept blocks; the caller typically
// invokes it in a go statement.
func AcceptOrderServiceClient(lis net.Listener, x OrderService) {
srv := rpc.NewServer()
if err := srv.RegisterName("OrderService", x); err != nil {
log.Fatal(err)
}
for {
conn, err := lis.Accept()
if err != nil {
log.Fatalf("lis.Accept(): %v\n", err)
}
go srv.ServeCodec(protorpc.NewServerCodec(conn))
}
}
// RegisterOrderService publish the given OrderService implementation on the server.
func RegisterOrderService(srv *rpc.Server, x OrderService) error {
if err := srv.RegisterName("OrderService", x); err != nil {
return err
}
return nil
}
// NewOrderServiceServer returns a new OrderService Server.
func NewOrderServiceServer(x OrderService) *rpc.Server {
srv := rpc.NewServer()
if err := srv.RegisterName("OrderService", x); err != nil {
log.Fatal(err)
}
return srv
}
// ListenAndServeOrderService listen announces on the local network address laddr
// and serves the given OrderService implementation.
func ListenAndServeOrderService(network, addr string, x OrderService) error {
lis, err := net.Listen(network, addr)
if err != nil {
return err
}
defer lis.Close()
srv := rpc.NewServer()
if err := srv.RegisterName("OrderService", x); err != nil {
return err
}
for {
conn, err := lis.Accept()
if err != nil {
log.Fatalf("lis.Accept(): %v\n", err)
}
go srv.ServeCodec(protorpc.NewServerCodec(conn))
}
}
type OrderServiceClient struct {
*rpc.Client
}
// NewOrderServiceClient returns a OrderService rpc.Client and stub to handle
// requests to the set of OrderService at the other end of the connection.
func NewOrderServiceClient(conn io.ReadWriteCloser) (*OrderServiceClient, *rpc.Client) {
c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
return &OrderServiceClient{c}, c
}
func (c *OrderServiceClient) Create(in *Request, out *Response) error {
return c.Call("OrderService.Create", in, out)
}
func (c *OrderServiceClient) CreateByCart(in *Request, out *Response) error {
return c.Call("OrderService.CreateByCart", in, out)
}
func (c *OrderServiceClient) Cancel(in *Request, out *Response) error {
return c.Call("OrderService.Cancel", in, out)
}
func (c *OrderServiceClient) AutoReceive(in *Request, out *Response) error {
return c.Call("OrderService.AutoReceive", in, out)
}
// DialOrderService connects to an OrderService at the specified network address.
func DialOrderService(network, addr string) (*OrderServiceClient, *rpc.Client, error) {
c, err := protorpc.Dial(network, addr)
if err != nil {
return nil, nil, err
}
return &OrderServiceClient{c}, c, nil
}
// DialOrderServiceTimeout connects to an OrderService at the specified network address.
func DialOrderServiceTimeout(network, addr string,
timeout time.Duration) (*OrderServiceClient, *rpc.Client, error) {
c, err := protorpc.DialTimeout(network, addr, timeout)
if err != nil {
return nil, nil, err
}
return &OrderServiceClient{c}, c, nil
}

+ 24
- 0
order.proto View File

@ -0,0 +1,24 @@
syntax = "proto3";
package orderrpcv2;
//
message Request {
string data = 1;
string time = 2;
string sign = 3;
}
//
message Response {
string data = 1;
string time = 2;
string sign = 3;
}
// rpc方法
service OrderService {
rpc create (Request) returns (Response); //
rpc createByCart (Request) returns (Response); //
rpc cancel (Request) returns (Response); //
rpc autoReceive(Request) returns(Response); //
}

Loading…
Cancel
Save