Goctl rpc patch (#117)
* remove mock generation * add: proto project import * update document * remove mock generation * add: proto project import * update document * remove NL * update document * optimize code * add test * add testmaster
parent
c32759d735
commit
0a9c427443
@ -0,0 +1,108 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: base.proto
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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 IdRequest struct {
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *IdRequest) Reset() { *m = IdRequest{} }
|
||||
func (m *IdRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*IdRequest) ProtoMessage() {}
|
||||
func (*IdRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_db1b6b0986796150, []int{0}
|
||||
}
|
||||
|
||||
func (m *IdRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_IdRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *IdRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_IdRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *IdRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_IdRequest.Merge(m, src)
|
||||
}
|
||||
func (m *IdRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_IdRequest.Size(m)
|
||||
}
|
||||
func (m *IdRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_IdRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_IdRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *IdRequest) GetId() string {
|
||||
if m != nil {
|
||||
return m.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type EmptyResponse struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *EmptyResponse) Reset() { *m = EmptyResponse{} }
|
||||
func (m *EmptyResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*EmptyResponse) ProtoMessage() {}
|
||||
func (*EmptyResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_db1b6b0986796150, []int{1}
|
||||
}
|
||||
|
||||
func (m *EmptyResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_EmptyResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *EmptyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_EmptyResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *EmptyResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_EmptyResponse.Merge(m, src)
|
||||
}
|
||||
func (m *EmptyResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_EmptyResponse.Size(m)
|
||||
}
|
||||
func (m *EmptyResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_EmptyResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_EmptyResponse proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*IdRequest)(nil), "base.IdRequest")
|
||||
proto.RegisterType((*EmptyResponse)(nil), "base.EmptyResponse")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("base.proto", fileDescriptor_db1b6b0986796150) }
|
||||
|
||||
var fileDescriptor_db1b6b0986796150 = []byte{
|
||||
// 91 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4a, 0x4a, 0x2c, 0x4e,
|
||||
0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x01, 0xb1, 0x95, 0xa4, 0xb9, 0x38, 0x3d, 0x53,
|
||||
0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0xf8, 0xb8, 0x98, 0x32, 0x53, 0x24, 0x18, 0x15,
|
||||
0x18, 0x35, 0x38, 0x83, 0x98, 0x32, 0x53, 0x94, 0xf8, 0xb9, 0x78, 0x5d, 0x73, 0x0b, 0x4a, 0x2a,
|
||||
0x83, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x93, 0xd8, 0xc0, 0x5a, 0x8d, 0x01, 0x01, 0x00,
|
||||
0x00, 0xff, 0xff, 0xe1, 0x39, 0x3c, 0x22, 0x48, 0x00, 0x00, 0x00,
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package base;
|
||||
|
||||
message IdRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message EmptyResponse {
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/console"
|
||||
)
|
||||
|
||||
func TestParseImport(t *testing.T) {
|
||||
src, _ := filepath.Abs("./test.proto")
|
||||
base, _ := filepath.Abs("./base.proto")
|
||||
imports, containsAny, err := parser.ParseImport(src)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, true, containsAny)
|
||||
assert.Equal(t, 1, len(imports))
|
||||
assert.Equal(t, "github.com/tal-tech/go-zero/tools/goctl/rpc", imports[0].PbImportName)
|
||||
assert.Equal(t, base, imports[0].OriginalProtoPath)
|
||||
}
|
||||
|
||||
func TestTransfer(t *testing.T) {
|
||||
src, _ := filepath.Abs("./test.proto")
|
||||
abs, _ := filepath.Abs("./test")
|
||||
imports, _, _ := parser.ParseImport(src)
|
||||
proto, err := parser.Transfer(src, abs, imports, console.NewConsole(false))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, len(proto.Service))
|
||||
assert.Equal(t, "Greeter", proto.Service[0].Name.Source())
|
||||
assert.Equal(t, 5, len(proto.Structure))
|
||||
data, ok := proto.Structure["map"]
|
||||
assert.Equal(t, true, ok)
|
||||
assert.Equal(t, "M", data.Field[0].Name.Source())
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/lang"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/console"
|
||||
)
|
||||
|
||||
func Transfer(proto, target string, externalImport []*Import, console console.Console) (*PbAst, error) {
|
||||
messageM := make(map[string]lang.PlaceholderType)
|
||||
enumM := make(map[string]*Enum)
|
||||
protoAst, err := parseProto(proto, messageM, enumM)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range externalImport {
|
||||
err = checkImport(item.OriginalProtoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
innerAst, err := parseProto(item.OriginalProtoPath, protoAst.Message, protoAst.Enum)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range innerAst.Message {
|
||||
protoAst.Message[k] = v
|
||||
}
|
||||
for k, v := range innerAst.Enum {
|
||||
protoAst.Enum[k] = v
|
||||
}
|
||||
}
|
||||
protoAst.Import = externalImport
|
||||
protoAst.PbSrc = filepath.Join(target, strings.TrimSuffix(filepath.Base(proto), ".proto")+".pb.go")
|
||||
return transfer(protoAst, console)
|
||||
}
|
||||
|
||||
func transfer(proto *Proto, console console.Console) (*PbAst, error) {
|
||||
parser := MustNewAstParser(proto, console)
|
||||
parse, err := parser.Parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parse, nil
|
||||
}
|
@ -0,0 +1,294 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/emicklei/proto"
|
||||
"github.com/tal-tech/go-zero/core/collection"
|
||||
"github.com/tal-tech/go-zero/core/lang"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
|
||||
)
|
||||
|
||||
const (
|
||||
AnyImport = "google/protobuf/any.proto"
|
||||
)
|
||||
|
||||
var (
|
||||
enumTypeTemplate = `{{.name}} int32`
|
||||
enumTemplate = `const (
|
||||
{{.element}}
|
||||
)`
|
||||
enumFiledTemplate = `{{.key}} {{.name}} = {{.value}}`
|
||||
)
|
||||
|
||||
type (
|
||||
MessageField struct {
|
||||
Type string
|
||||
Name stringx.String
|
||||
}
|
||||
Message struct {
|
||||
Name stringx.String
|
||||
Element []*MessageField
|
||||
*proto.Message
|
||||
}
|
||||
Enum struct {
|
||||
Name stringx.String
|
||||
Element []*EnumField
|
||||
*proto.Enum
|
||||
}
|
||||
EnumField struct {
|
||||
Key string
|
||||
Value int
|
||||
}
|
||||
|
||||
Proto struct {
|
||||
Package string
|
||||
Import []*Import
|
||||
PbSrc string
|
||||
ContainsAny bool
|
||||
Message map[string]lang.PlaceholderType
|
||||
Enum map[string]*Enum
|
||||
}
|
||||
Import struct {
|
||||
ProtoImportName string
|
||||
PbImportName string
|
||||
OriginalDir string
|
||||
OriginalProtoPath string
|
||||
OriginalPbPath string
|
||||
BridgeImport string
|
||||
exists bool
|
||||
//xx.proto
|
||||
protoName string
|
||||
// xx.pb.go
|
||||
pbName string
|
||||
}
|
||||
)
|
||||
|
||||
func checkImport(src string) error {
|
||||
r, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
parser := proto.NewParser(r)
|
||||
parseRet, err := parser.Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var base = filepath.Base(src)
|
||||
proto.Walk(parseRet, proto.WithImport(func(i *proto.Import) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("%v:%v the external proto cannot import other proto files", base, i.Position.Line)
|
||||
}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func ParseImport(src string) ([]*Import, bool, error) {
|
||||
bridgeImportM := make(map[string]string)
|
||||
r, err := os.Open(src)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
workDir := filepath.Dir(src)
|
||||
parser := proto.NewParser(r)
|
||||
parseRet, err := parser.Parse()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
protoImportSet := collection.NewSet()
|
||||
var containsAny bool
|
||||
proto.Walk(parseRet, proto.WithImport(func(i *proto.Import) {
|
||||
if i.Filename == AnyImport {
|
||||
containsAny = true
|
||||
return
|
||||
}
|
||||
protoImportSet.AddStr(i.Filename)
|
||||
if i.Comment != nil {
|
||||
lines := i.Comment.Lines
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if !strings.HasPrefix(line, "@") {
|
||||
continue
|
||||
}
|
||||
line = strings.TrimPrefix(line, "@")
|
||||
bridgeImportM[i.Filename] = line
|
||||
}
|
||||
}
|
||||
}))
|
||||
var importList []*Import
|
||||
|
||||
for _, item := range protoImportSet.KeysStr() {
|
||||
pb := strings.TrimSuffix(filepath.Base(item), filepath.Ext(item)) + ".pb.go"
|
||||
var pbImportName, brideImport string
|
||||
if v, ok := bridgeImportM[item]; ok {
|
||||
pbImportName = v
|
||||
brideImport = "M" + item + "=" + v
|
||||
} else {
|
||||
pbImportName = item
|
||||
}
|
||||
var impo = Import{
|
||||
ProtoImportName: item,
|
||||
PbImportName: pbImportName,
|
||||
BridgeImport: brideImport,
|
||||
}
|
||||
protoSource := filepath.Join(workDir, item)
|
||||
pbSource := filepath.Join(filepath.Dir(protoSource), pb)
|
||||
if util.FileExists(protoSource) && util.FileExists(pbSource) {
|
||||
impo.OriginalProtoPath = protoSource
|
||||
impo.OriginalPbPath = pbSource
|
||||
impo.OriginalDir = filepath.Dir(protoSource)
|
||||
impo.exists = true
|
||||
impo.protoName = filepath.Base(item)
|
||||
impo.pbName = pb
|
||||
} else {
|
||||
return nil, false, fmt.Errorf("「%v」: import must be found in the relative directory of 「%v」", item, filepath.Base(src))
|
||||
}
|
||||
importList = append(importList, &impo)
|
||||
}
|
||||
|
||||
return importList, containsAny, nil
|
||||
}
|
||||
|
||||
func parseProto(src string, messageM map[string]lang.PlaceholderType, enumM map[string]*Enum) (*Proto, error) {
|
||||
if !filepath.IsAbs(src) {
|
||||
return nil, fmt.Errorf("expected absolute path,but found: %v", src)
|
||||
}
|
||||
|
||||
r, err := os.Open(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
parser := proto.NewParser(r)
|
||||
parseRet, err := parser.Parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// xx.proto
|
||||
fileBase := filepath.Base(src)
|
||||
var resp Proto
|
||||
|
||||
proto.Walk(parseRet, proto.WithPackage(func(p *proto.Package) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(resp.Package) != 0 {
|
||||
err = fmt.Errorf("%v:%v duplicate package「%v」", fileBase, p.Position.Line, p.Name)
|
||||
}
|
||||
|
||||
if len(p.Name) == 0 {
|
||||
err = errors.New("package not found")
|
||||
}
|
||||
|
||||
resp.Package = p.Name
|
||||
}), proto.WithMessage(func(message *proto.Message) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range message.Elements {
|
||||
switch item.(type) {
|
||||
case *proto.NormalField, *proto.MapField, *proto.Comment:
|
||||
continue
|
||||
default:
|
||||
err = fmt.Errorf("%v: unsupport inline declaration", fileBase)
|
||||
return
|
||||
}
|
||||
}
|
||||
name := stringx.From(message.Name)
|
||||
if _, ok := messageM[name.Lower()]; ok {
|
||||
err = fmt.Errorf("%v:%v duplicate message 「%v」", fileBase, message.Position.Line, message.Name)
|
||||
return
|
||||
}
|
||||
|
||||
messageM[name.Lower()] = lang.Placeholder
|
||||
}), proto.WithEnum(func(enum *proto.Enum) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var node Enum
|
||||
node.Enum = enum
|
||||
node.Name = stringx.From(enum.Name)
|
||||
for _, item := range enum.Elements {
|
||||
v, ok := item.(*proto.EnumField)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
node.Element = append(node.Element, &EnumField{
|
||||
Key: v.Name,
|
||||
Value: v.Integer,
|
||||
})
|
||||
}
|
||||
if _, ok := enumM[node.Name.Lower()]; ok {
|
||||
err = fmt.Errorf("%v:%v duplicate enum 「%v」", fileBase, node.Position.Line, node.Name.Source())
|
||||
return
|
||||
}
|
||||
|
||||
lower := stringx.From(enum.Name).Lower()
|
||||
enumM[lower] = &node
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Message = messageM
|
||||
resp.Enum = enumM
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (e *Enum) GenEnumCode() (string, error) {
|
||||
var element []string
|
||||
for _, item := range e.Element {
|
||||
code, err := item.GenEnumFieldCode(e.Name.Source())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
element = append(element, code)
|
||||
}
|
||||
buffer, err := util.With("enum").Parse(enumTemplate).Execute(map[string]interface{}{
|
||||
"element": strings.Join(element, util.NL),
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
func (e *Enum) GenEnumTypeCode() (string, error) {
|
||||
buffer, err := util.With("enumAlias").Parse(enumTypeTemplate).Execute(map[string]interface{}{
|
||||
"name": e.Name.Source(),
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
func (e *EnumField) GenEnumFieldCode(parentName string) (string, error) {
|
||||
buffer, err := util.With("enumField").Parse(enumFiledTemplate).Execute(map[string]interface{}{
|
||||
"key": e.Key,
|
||||
"name": parentName,
|
||||
"value": e.Value,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buffer.String(), nil
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
syntax = "proto3";
|
||||
// protoc -I=${GOPATH}/src -I=. test.proto --go_out=plugins=grpc,Mbase.proto=github.com/tal-tech/go-zero/tools/goctl/rpc:./test
|
||||
package test;
|
||||
// @github.com/tal-tech/go-zero/tools/goctl/rpc
|
||||
import "base.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
message request {
|
||||
string name = 1;
|
||||
}
|
||||
enum Gender{
|
||||
UNKNOWN = 0;
|
||||
MALE = 1;
|
||||
FEMALE = 2;
|
||||
}
|
||||
message response {
|
||||
string greet = 1;
|
||||
google.protobuf.Any data = 2;
|
||||
|
||||
}
|
||||
message map {
|
||||
map<string, string> m = 1;
|
||||
}
|
||||
|
||||
service Greeter {
|
||||
rpc greet(request) returns (response);
|
||||
rpc idRequest(base.IdRequest)returns(base.EmptyResponse);
|
||||
}
|
@ -0,0 +1,331 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: test.proto
|
||||
|
||||
// protoc -I=${GOPATH}/src -I=. test.proto --go_out=plugins=grpc,Mbase.proto=github.com/tal-tech/go-zero/tools/goctl/rpc:./test
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
rpc "github.com/tal-tech/go-zero/tools/goctl/rpc"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||
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 Gender int32
|
||||
|
||||
const (
|
||||
Gender_UNKNOWN Gender = 0
|
||||
Gender_MALE Gender = 1
|
||||
Gender_FEMALE Gender = 2
|
||||
)
|
||||
|
||||
var Gender_name = map[int32]string{
|
||||
0: "UNKNOWN",
|
||||
1: "MALE",
|
||||
2: "FEMALE",
|
||||
}
|
||||
|
||||
var Gender_value = map[string]int32{
|
||||
"UNKNOWN": 0,
|
||||
"MALE": 1,
|
||||
"FEMALE": 2,
|
||||
}
|
||||
|
||||
func (x Gender) String() string {
|
||||
return proto.EnumName(Gender_name, int32(x))
|
||||
}
|
||||
|
||||
func (Gender) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_c161fcfdc0c3ff1e, []int{0}
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Request) Reset() { *m = Request{} }
|
||||
func (m *Request) String() string { return proto.CompactTextString(m) }
|
||||
func (*Request) ProtoMessage() {}
|
||||
func (*Request) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_c161fcfdc0c3ff1e, []int{0}
|
||||
}
|
||||
|
||||
func (m *Request) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Request.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Request.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Request) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Request.Merge(m, src)
|
||||
}
|
||||
func (m *Request) XXX_Size() int {
|
||||
return xxx_messageInfo_Request.Size(m)
|
||||
}
|
||||
func (m *Request) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Request.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Request proto.InternalMessageInfo
|
||||
|
||||
func (m *Request) GetName() string {
|
||||
if m != nil {
|
||||
return m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Greet string `protobuf:"bytes,1,opt,name=greet,proto3" json:"greet,omitempty"`
|
||||
Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Response) Reset() { *m = Response{} }
|
||||
func (m *Response) String() string { return proto.CompactTextString(m) }
|
||||
func (*Response) ProtoMessage() {}
|
||||
func (*Response) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_c161fcfdc0c3ff1e, []int{1}
|
||||
}
|
||||
|
||||
func (m *Response) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Response.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Response.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Response) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Response.Merge(m, src)
|
||||
}
|
||||
func (m *Response) XXX_Size() int {
|
||||
return xxx_messageInfo_Response.Size(m)
|
||||
}
|
||||
func (m *Response) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Response.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Response proto.InternalMessageInfo
|
||||
|
||||
func (m *Response) GetGreet() string {
|
||||
if m != nil {
|
||||
return m.Greet
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Response) GetData() *anypb.Any {
|
||||
if m != nil {
|
||||
return m.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Map struct {
|
||||
M map[string]string `protobuf:"bytes,1,rep,name=m,proto3" json:"m,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Map) Reset() { *m = Map{} }
|
||||
func (m *Map) String() string { return proto.CompactTextString(m) }
|
||||
func (*Map) ProtoMessage() {}
|
||||
func (*Map) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_c161fcfdc0c3ff1e, []int{2}
|
||||
}
|
||||
|
||||
func (m *Map) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Map.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Map) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Map.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Map) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Map.Merge(m, src)
|
||||
}
|
||||
func (m *Map) XXX_Size() int {
|
||||
return xxx_messageInfo_Map.Size(m)
|
||||
}
|
||||
func (m *Map) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Map.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Map proto.InternalMessageInfo
|
||||
|
||||
func (m *Map) GetM() map[string]string {
|
||||
if m != nil {
|
||||
return m.M
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("test.Gender", Gender_name, Gender_value)
|
||||
proto.RegisterType((*Request)(nil), "test.request")
|
||||
proto.RegisterType((*Response)(nil), "test.response")
|
||||
proto.RegisterType((*Map)(nil), "test.map")
|
||||
proto.RegisterMapType((map[string]string)(nil), "test.map.MEntry")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("test.proto", fileDescriptor_c161fcfdc0c3ff1e) }
|
||||
|
||||
var fileDescriptor_c161fcfdc0c3ff1e = []byte{
|
||||
// 301 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x90, 0x4f, 0x4b, 0xc3, 0x40,
|
||||
0x10, 0xc5, 0xdd, 0x36, 0xa6, 0xed, 0x14, 0x35, 0x8c, 0x3d, 0xd4, 0x80, 0x52, 0x7a, 0x90, 0xa0,
|
||||
0xb0, 0xc5, 0xea, 0x41, 0xbc, 0xf5, 0x10, 0x8b, 0x7f, 0x5a, 0x21, 0x20, 0x1e, 0x3c, 0x6d, 0xc9,
|
||||
0x58, 0xc4, 0xee, 0x26, 0x6e, 0xb6, 0x42, 0xbe, 0xbd, 0x64, 0x77, 0x73, 0x7b, 0xbf, 0xd9, 0x59,
|
||||
0xde, 0x9b, 0x07, 0x60, 0xa8, 0x32, 0xbc, 0xd4, 0x85, 0x29, 0x30, 0x68, 0x74, 0x0c, 0x1b, 0x51,
|
||||
0x91, 0x9b, 0xc4, 0x67, 0xdb, 0xa2, 0xd8, 0xee, 0x68, 0x66, 0x69, 0xb3, 0xff, 0x9a, 0x09, 0x55,
|
||||
0xbb, 0xa7, 0xe9, 0x39, 0xf4, 0x34, 0xfd, 0xee, 0xa9, 0x32, 0x88, 0x10, 0x28, 0x21, 0x69, 0xcc,
|
||||
0x26, 0x2c, 0x19, 0x64, 0x56, 0x4f, 0x9f, 0xa1, 0xaf, 0xa9, 0x2a, 0x0b, 0x55, 0x11, 0x8e, 0xe0,
|
||||
0x70, 0xab, 0x89, 0x8c, 0x5f, 0x70, 0x80, 0x09, 0x04, 0xb9, 0x30, 0x62, 0xdc, 0x99, 0xb0, 0x64,
|
||||
0x38, 0x1f, 0x71, 0x67, 0xc5, 0x5b, 0x2b, 0xbe, 0x50, 0x75, 0x66, 0x37, 0xa6, 0x9f, 0xd0, 0x95,
|
||||
0xa2, 0xc4, 0x0b, 0x60, 0x72, 0xcc, 0x26, 0xdd, 0x64, 0x38, 0x8f, 0xb8, 0x8d, 0x2d, 0x45, 0xc9,
|
||||
0x57, 0xa9, 0x32, 0xba, 0xce, 0x98, 0x8c, 0xef, 0x20, 0x74, 0x80, 0x11, 0x74, 0x7f, 0xa8, 0xf6,
|
||||
0x76, 0x8d, 0x6c, 0x22, 0xfc, 0x89, 0xdd, 0x9e, 0xac, 0xdb, 0x20, 0x73, 0xf0, 0xd0, 0xb9, 0x67,
|
||||
0x57, 0xd7, 0x10, 0x2e, 0x49, 0xe5, 0xa4, 0x71, 0x08, 0xbd, 0xf7, 0xf5, 0xcb, 0xfa, 0xed, 0x63,
|
||||
0x1d, 0x1d, 0x60, 0x1f, 0x82, 0xd5, 0xe2, 0x35, 0x8d, 0x18, 0x02, 0x84, 0x8f, 0xa9, 0xd5, 0x9d,
|
||||
0x79, 0x0e, 0xbd, 0x65, 0x13, 0x9e, 0x34, 0x5e, 0xfa, 0xa3, 0xf0, 0xc8, 0x65, 0xf1, 0x65, 0xc4,
|
||||
0xc7, 0x2d, 0xfa, 0xe3, 0x6f, 0x60, 0xf0, 0x9d, 0x67, 0xbe, 0xa9, 0x13, 0x6e, 0xcb, 0x7d, 0x6a,
|
||||
0x07, 0xf1, 0xa9, 0x1b, 0xa4, 0xb2, 0x34, 0x75, 0xe6, 0xbf, 0x6c, 0x42, 0xdb, 0xc1, 0xed, 0x7f,
|
||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x7a, 0x3b, 0x55, 0x9c, 0x01, 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
|
||||
|
||||
// GreeterClient is the client API for Greeter service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type GreeterClient interface {
|
||||
Greet(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
|
||||
IdRequest(ctx context.Context, in *rpc.IdRequest, opts ...grpc.CallOption) (*rpc.EmptyResponse, error)
|
||||
}
|
||||
|
||||
type greeterClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewGreeterClient(cc *grpc.ClientConn) GreeterClient {
|
||||
return &greeterClient{cc}
|
||||
}
|
||||
|
||||
func (c *greeterClient) Greet(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
|
||||
out := new(Response)
|
||||
err := c.cc.Invoke(ctx, "/test.Greeter/greet", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *greeterClient) IdRequest(ctx context.Context, in *rpc.IdRequest, opts ...grpc.CallOption) (*rpc.EmptyResponse, error) {
|
||||
out := new(rpc.EmptyResponse)
|
||||
err := c.cc.Invoke(ctx, "/test.Greeter/idRequest", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GreeterServer is the server API for Greeter service.
|
||||
type GreeterServer interface {
|
||||
Greet(context.Context, *Request) (*Response, error)
|
||||
IdRequest(context.Context, *rpc.IdRequest) (*rpc.EmptyResponse, error)
|
||||
}
|
||||
|
||||
// UnimplementedGreeterServer can be embedded to have forward compatible implementations.
|
||||
type UnimplementedGreeterServer struct {
|
||||
}
|
||||
|
||||
func (*UnimplementedGreeterServer) Greet(ctx context.Context, req *Request) (*Response, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Greet not implemented")
|
||||
}
|
||||
func (*UnimplementedGreeterServer) IdRequest(ctx context.Context, req *rpc.IdRequest) (*rpc.EmptyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method IdRequest not implemented")
|
||||
}
|
||||
|
||||
func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) {
|
||||
s.RegisterService(&_Greeter_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Greeter_Greet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Request)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(GreeterServer).Greet(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/test.Greeter/Greet",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(GreeterServer).Greet(ctx, req.(*Request))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Greeter_IdRequest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(rpc.IdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(GreeterServer).IdRequest(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/test.Greeter/IdRequest",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(GreeterServer).IdRequest(ctx, req.(*rpc.IdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Greeter_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "test.Greeter",
|
||||
HandlerType: (*GreeterServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "greet",
|
||||
Handler: _Greeter_Greet_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "idRequest",
|
||||
Handler: _Greeter_IdRequest_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "test.proto",
|
||||
}
|
Loading…
Reference in New Issue