Commit db9cf9c1 authored by “李磊”'s avatar “李磊”
Browse files

Initial commit

parents
# rpcservice
### 生成文件方式
```
执行./auto_gen.sh "构建目录" 即自动创建成功
例如: ./auto_gen.sh plugin
```
#!/bin/bash -e
if [ $# != 1 ];then
echo "usage:$0 proto_dir"
exit 1
fi
echo "generate protoc"
docker run --rm -v $(pwd):/rpcserver harbor.linkfog.cn/basegroup/grpc:1.0 bash /rpcserver/build/build.sh $1
echo "generate protoc finished"
#!/bin/bash -e
PROTO_DIR=/rpcserver/$1
protoc -I=${PROTO_DIR} --go_out=plugins=grpc:${PROTO_DIR} ${PROTO_DIR}/*.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: plugin.proto
package proto
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Req struct {
Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Req) Reset() { *m = Req{} }
func (m *Req) String() string { return proto.CompactTextString(m) }
func (*Req) ProtoMessage() {}
func (*Req) Descriptor() ([]byte, []int) {
return fileDescriptor_22a625af4bc1cc87, []int{0}
}
func (m *Req) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Req.Unmarshal(m, b)
}
func (m *Req) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Req.Marshal(b, m, deterministic)
}
func (m *Req) XXX_Merge(src proto.Message) {
xxx_messageInfo_Req.Merge(m, src)
}
func (m *Req) XXX_Size() int {
return xxx_messageInfo_Req.Size(m)
}
func (m *Req) XXX_DiscardUnknown() {
xxx_messageInfo_Req.DiscardUnknown(m)
}
var xxx_messageInfo_Req proto.InternalMessageInfo
func (m *Req) GetHeader() *Header {
if m != nil {
return m.Header
}
return nil
}
func (m *Req) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
type Res struct {
Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"`
Code int32 `protobuf:"varint,2,opt,name=Code,proto3" json:"Code,omitempty"`
Desc string `protobuf:"bytes,3,opt,name=Desc,proto3" json:"Desc,omitempty"`
Data []byte `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Res) Reset() { *m = Res{} }
func (m *Res) String() string { return proto.CompactTextString(m) }
func (*Res) ProtoMessage() {}
func (*Res) Descriptor() ([]byte, []int) {
return fileDescriptor_22a625af4bc1cc87, []int{1}
}
func (m *Res) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Res.Unmarshal(m, b)
}
func (m *Res) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Res.Marshal(b, m, deterministic)
}
func (m *Res) XXX_Merge(src proto.Message) {
xxx_messageInfo_Res.Merge(m, src)
}
func (m *Res) XXX_Size() int {
return xxx_messageInfo_Res.Size(m)
}
func (m *Res) XXX_DiscardUnknown() {
xxx_messageInfo_Res.DiscardUnknown(m)
}
var xxx_messageInfo_Res proto.InternalMessageInfo
func (m *Res) GetHeader() *Header {
if m != nil {
return m.Header
}
return nil
}
func (m *Res) GetCode() int32 {
if m != nil {
return m.Code
}
return 0
}
func (m *Res) GetDesc() string {
if m != nil {
return m.Desc
}
return ""
}
func (m *Res) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
type FileStream struct {
Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"`
Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"`
Purpose string `protobuf:"bytes,3,opt,name=Purpose,proto3" json:"Purpose,omitempty"`
TotalSize int64 `protobuf:"varint,4,opt,name=TotalSize,proto3" json:"TotalSize,omitempty"`
TotalPart int64 `protobuf:"varint,5,opt,name=TotalPart,proto3" json:"TotalPart,omitempty"`
Part int64 `protobuf:"varint,6,opt,name=Part,proto3" json:"Part,omitempty"`
Data []byte `protobuf:"bytes,7,opt,name=Data,proto3" json:"Data,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *FileStream) Reset() { *m = FileStream{} }
func (m *FileStream) String() string { return proto.CompactTextString(m) }
func (*FileStream) ProtoMessage() {}
func (*FileStream) Descriptor() ([]byte, []int) {
return fileDescriptor_22a625af4bc1cc87, []int{2}
}
func (m *FileStream) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_FileStream.Unmarshal(m, b)
}
func (m *FileStream) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_FileStream.Marshal(b, m, deterministic)
}
func (m *FileStream) XXX_Merge(src proto.Message) {
xxx_messageInfo_FileStream.Merge(m, src)
}
func (m *FileStream) XXX_Size() int {
return xxx_messageInfo_FileStream.Size(m)
}
func (m *FileStream) XXX_DiscardUnknown() {
xxx_messageInfo_FileStream.DiscardUnknown(m)
}
var xxx_messageInfo_FileStream proto.InternalMessageInfo
func (m *FileStream) GetHeader() *Header {
if m != nil {
return m.Header
}
return nil
}
func (m *FileStream) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *FileStream) GetPurpose() string {
if m != nil {
return m.Purpose
}
return ""
}
func (m *FileStream) GetTotalSize() int64 {
if m != nil {
return m.TotalSize
}
return 0
}
func (m *FileStream) GetTotalPart() int64 {
if m != nil {
return m.TotalPart
}
return 0
}
func (m *FileStream) GetPart() int64 {
if m != nil {
return m.Part
}
return 0
}
func (m *FileStream) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
type Header struct {
UUID string `protobuf:"bytes,1,opt,name=UUID,proto3" json:"UUID,omitempty"`
Timestamp int64 `protobuf:"varint,2,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"`
From string `protobuf:"bytes,3,opt,name=From,proto3" json:"From,omitempty"`
To string `protobuf:"bytes,4,opt,name=To,proto3" json:"To,omitempty"`
Func string `protobuf:"bytes,5,opt,name=Func,proto3" json:"Func,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Header) Reset() { *m = Header{} }
func (m *Header) String() string { return proto.CompactTextString(m) }
func (*Header) ProtoMessage() {}
func (*Header) Descriptor() ([]byte, []int) {
return fileDescriptor_22a625af4bc1cc87, []int{3}
}
func (m *Header) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Header.Unmarshal(m, b)
}
func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Header.Marshal(b, m, deterministic)
}
func (m *Header) XXX_Merge(src proto.Message) {
xxx_messageInfo_Header.Merge(m, src)
}
func (m *Header) XXX_Size() int {
return xxx_messageInfo_Header.Size(m)
}
func (m *Header) XXX_DiscardUnknown() {
xxx_messageInfo_Header.DiscardUnknown(m)
}
var xxx_messageInfo_Header proto.InternalMessageInfo
func (m *Header) GetUUID() string {
if m != nil {
return m.UUID
}
return ""
}
func (m *Header) GetTimestamp() int64 {
if m != nil {
return m.Timestamp
}
return 0
}
func (m *Header) GetFrom() string {
if m != nil {
return m.From
}
return ""
}
func (m *Header) GetTo() string {
if m != nil {
return m.To
}
return ""
}
func (m *Header) GetFunc() string {
if m != nil {
return m.Func
}
return ""
}
func init() {
proto.RegisterType((*Req)(nil), "proto.Req")
proto.RegisterType((*Res)(nil), "proto.Res")
proto.RegisterType((*FileStream)(nil), "proto.FileStream")
proto.RegisterType((*Header)(nil), "proto.Header")
}
func init() { proto.RegisterFile("plugin.proto", fileDescriptor_22a625af4bc1cc87) }
var fileDescriptor_22a625af4bc1cc87 = []byte{
// 326 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x51, 0xc1, 0x4a, 0xc3, 0x40,
0x10, 0x75, 0xdb, 0x34, 0x35, 0x63, 0x15, 0x9c, 0x53, 0x10, 0x0f, 0x21, 0x20, 0xe4, 0x62, 0x91,
0xfa, 0x03, 0x42, 0x4b, 0xd1, 0x8b, 0x94, 0x6d, 0xfb, 0x01, 0x6b, 0x3b, 0xd8, 0x40, 0x92, 0x4d,
0x37, 0x9b, 0x8b, 0xe0, 0xe7, 0xf9, 0x5f, 0xb2, 0xd3, 0xa4, 0x8d, 0x07, 0x0f, 0x3d, 0xe5, 0xcd,
0x7b, 0x93, 0xf7, 0x66, 0x66, 0x61, 0x54, 0x66, 0xf5, 0x67, 0x5a, 0x8c, 0x4b, 0xa3, 0xad, 0xc6,
0x01, 0x7f, 0xe2, 0x17, 0xe8, 0x4b, 0xda, 0xe3, 0x03, 0xf8, 0xaf, 0xa4, 0xb6, 0x64, 0x42, 0x11,
0x89, 0xe4, 0x6a, 0x72, 0x7d, 0xe8, 0x1a, 0x1f, 0x48, 0xd9, 0x88, 0x88, 0xe0, 0xcd, 0x94, 0x55,
0x61, 0x2f, 0x12, 0xc9, 0x48, 0x32, 0x8e, 0x77, 0xce, 0xa1, 0x3a, 0xc3, 0x61, 0xaa, 0xb7, 0xc4,
0x0e, 0x03, 0xc9, 0x98, 0x5d, 0xa9, 0xda, 0x84, 0xfd, 0x48, 0x24, 0x81, 0x64, 0x7c, 0x4c, 0xf2,
0x3a, 0x49, 0x3f, 0x02, 0x60, 0x9e, 0x66, 0xb4, 0xb4, 0x86, 0x54, 0x7e, 0x46, 0xe2, 0xbb, 0xca,
0x0f, 0x89, 0x81, 0x64, 0x8c, 0x21, 0x0c, 0x17, 0xb5, 0x29, 0x75, 0x45, 0x4d, 0x68, 0x5b, 0xe2,
0x3d, 0x04, 0x2b, 0x6d, 0x55, 0xb6, 0x4c, 0xbf, 0x88, 0xc3, 0xfb, 0xf2, 0x44, 0x1c, 0xd5, 0x85,
0x32, 0x36, 0x1c, 0x74, 0x54, 0x47, 0xb8, 0x24, 0x16, 0x7c, 0x16, 0xbc, 0x96, 0xe3, 0x3d, 0x86,
0x9d, 0x3d, 0x0c, 0x74, 0x66, 0x5b, 0xaf, 0xdf, 0x66, 0xbc, 0x40, 0x20, 0x19, 0x73, 0x46, 0x9a,
0x53, 0x65, 0x55, 0x5e, 0xf2, 0xd0, 0x2e, 0xa3, 0x25, 0xdc, 0x1f, 0x73, 0xa3, 0xf3, 0xf6, 0x56,
0x0e, 0xe3, 0x0d, 0xf4, 0x56, 0x9a, 0x87, 0x0d, 0x64, 0x6f, 0xa5, 0xb9, 0xa7, 0x2e, 0x36, 0x3c,
0xa0, 0xeb, 0xa9, 0x8b, 0xcd, 0xe4, 0x1b, 0xfc, 0x05, 0x3f, 0x3f, 0x46, 0xe0, 0x4d, 0x55, 0x96,
0x21, 0x34, 0xe7, 0x92, 0xb4, 0xbf, 0x3b, 0xe1, 0x2a, 0xbe, 0xc0, 0x47, 0xb8, 0x5c, 0x52, 0xb1,
0x75, 0xa7, 0xc6, 0xdb, 0x46, 0x39, 0xdd, 0xfd, 0x6f, 0x73, 0x22, 0x30, 0x06, 0x6f, 0xba, 0x53,
0xf6, 0x7f, 0xc3, 0x27, 0xf1, 0xe1, 0x73, 0xf9, 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x6c,
0xc9, 0x75, 0x84, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// PluginClient is the client API for Plugin service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type PluginClient interface {
Call(ctx context.Context, in *Req, opts ...grpc.CallOption) (*Res, error)
SendFile(ctx context.Context, opts ...grpc.CallOption) (Plugin_SendFileClient, error)
Chat(ctx context.Context, in *Req, opts ...grpc.CallOption) (Plugin_ChatClient, error)
}
type pluginClient struct {
cc *grpc.ClientConn
}
func NewPluginClient(cc *grpc.ClientConn) PluginClient {
return &pluginClient{cc}
}
func (c *pluginClient) Call(ctx context.Context, in *Req, opts ...grpc.CallOption) (*Res, error) {
out := new(Res)
err := c.cc.Invoke(ctx, "/proto.Plugin/Call", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *pluginClient) SendFile(ctx context.Context, opts ...grpc.CallOption) (Plugin_SendFileClient, error) {
stream, err := c.cc.NewStream(ctx, &_Plugin_serviceDesc.Streams[0], "/proto.Plugin/SendFile", opts...)
if err != nil {
return nil, err
}
x := &pluginSendFileClient{stream}
return x, nil
}
type Plugin_SendFileClient interface {
Send(*FileStream) error
CloseAndRecv() (*Res, error)
grpc.ClientStream
}
type pluginSendFileClient struct {
grpc.ClientStream
}
func (x *pluginSendFileClient) Send(m *FileStream) error {
return x.ClientStream.SendMsg(m)
}
func (x *pluginSendFileClient) CloseAndRecv() (*Res, error) {
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
m := new(Res)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *pluginClient) Chat(ctx context.Context, in *Req, opts ...grpc.CallOption) (Plugin_ChatClient, error) {
stream, err := c.cc.NewStream(ctx, &_Plugin_serviceDesc.Streams[1], "/proto.Plugin/Chat", opts...)
if err != nil {
return nil, err
}
x := &pluginChatClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type Plugin_ChatClient interface {
Recv() (*Res, error)
grpc.ClientStream
}
type pluginChatClient struct {
grpc.ClientStream
}
func (x *pluginChatClient) Recv() (*Res, error) {
m := new(Res)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// PluginServer is the server API for Plugin service.
type PluginServer interface {
Call(context.Context, *Req) (*Res, error)
SendFile(Plugin_SendFileServer) error
Chat(*Req, Plugin_ChatServer) error
}
// UnimplementedPluginServer can be embedded to have forward compatible implementations.
type UnimplementedPluginServer struct {
}
func (*UnimplementedPluginServer) Call(ctx context.Context, req *Req) (*Res, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (*UnimplementedPluginServer) SendFile(srv Plugin_SendFileServer) error {
return status.Errorf(codes.Unimplemented, "method SendFile not implemented")
}
func (*UnimplementedPluginServer) Chat(req *Req, srv Plugin_ChatServer) error {
return status.Errorf(codes.Unimplemented, "method Chat not implemented")
}
func RegisterPluginServer(s *grpc.Server, srv PluginServer) {
s.RegisterService(&_Plugin_serviceDesc, srv)
}
func _Plugin_Call_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Req)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PluginServer).Call(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Plugin/Call",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PluginServer).Call(ctx, req.(*Req))
}
return interceptor(ctx, in, info, handler)
}
func _Plugin_SendFile_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(PluginServer).SendFile(&pluginSendFileServer{stream})
}
type Plugin_SendFileServer interface {
SendAndClose(*Res) error
Recv() (*FileStream, error)
grpc.ServerStream
}
type pluginSendFileServer struct {
grpc.ServerStream
}
func (x *pluginSendFileServer) SendAndClose(m *Res) error {
return x.ServerStream.SendMsg(m)
}
func (x *pluginSendFileServer) Recv() (*FileStream, error) {
m := new(FileStream)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Plugin_Chat_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(Req)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(PluginServer).Chat(m, &pluginChatServer{stream})
}
type Plugin_ChatServer interface {
Send(*Res) error
grpc.ServerStream
}
type pluginChatServer struct {
grpc.ServerStream
}
func (x *pluginChatServer) Send(m *Res) error {
return x.ServerStream.SendMsg(m)
}
var _Plugin_serviceDesc = grpc.ServiceDesc{
ServiceName: "proto.Plugin",
HandlerType: (*PluginServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Call",
Handler: _Plugin_Call_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "SendFile",
Handler: _Plugin_SendFile_Handler,
ClientStreams: true,
},
{
StreamName: "Chat",
Handler: _Plugin_Chat_Handler,
ServerStreams: true,
},
},
Metadata: "plugin.proto",
}
syntax = "proto3";
package proto;
service Plugin {
rpc Call(Req) returns (Res) {}
rpc SendFile(stream FileStream) returns (Res) {}
rpc Chat(Req) returns (stream Res) {}
}
message Req {
Header Header = 1;
bytes Data = 2;
}
message Res {
Header Header = 1;
int32 Code = 2;
string Desc = 3;
bytes Data = 4;
}
message FileStream {
Header Header = 1;
string Name = 2;
string Purpose = 3;
int64 TotalSize = 4;
int64 TotalPart = 5;
int64 Part = 6;
bytes Data = 7;
}
message Header {
string UUID = 1;
int64 Timestamp = 2;
string From = 3;
string To = 4;
string Func = 5;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment