@@ -16,15 +16,15 @@ const (
16
16
regexpPackage = protogen .GoImportPath ("regexp" )
17
17
contextPackage = protogen .GoImportPath ("context" )
18
18
protoPackage = protogen .GoImportPath ("google.golang.org/protobuf/proto" )
19
- grpcPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/grpc " )
19
+ cgrpcPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/cgrpc " )
20
20
logPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/log" )
21
21
commonPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/util/common" )
22
22
metadataPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/metadata" )
23
23
errorPackage = protogen .GoImportPath ("github.com/chenjie199234/Corelib/error" )
24
24
)
25
25
26
26
func generateFile (gen * protogen.Plugin , file * protogen.File ) * protogen.GeneratedFile {
27
- filename := file .GeneratedFilenamePrefix + "_grpc .pb.go"
27
+ filename := file .GeneratedFilenamePrefix + "_cgrpc .pb.go"
28
28
g := gen .NewGeneratedFile (filename , file .GoImportPath )
29
29
30
30
genFileComment (gen , file , g )
@@ -42,7 +42,7 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
42
42
}
43
43
func genFileComment (gen * protogen.Plugin , file * protogen.File , g * protogen.GeneratedFile ) {
44
44
//add version comments
45
- g .P ("// Code generated by protoc-gen-go-grpc . DO NOT EDIT." )
45
+ g .P ("// Code generated by protoc-gen-go-cgrpc . DO NOT EDIT." )
46
46
g .P ("// version:" )
47
47
protocVersion := "(unknown)"
48
48
if v := gen .Request .GetCompilerVersion (); v != nil {
@@ -51,7 +51,7 @@ func genFileComment(gen *protogen.Plugin, file *protogen.File, g *protogen.Gener
51
51
protocVersion += "-" + s
52
52
}
53
53
}
54
- g .P ("// \t protoc-gen-go-grpc " , version )
54
+ g .P ("// \t protoc-gen-go-cgrpc " , version )
55
55
g .P ("// \t protoc " , protocVersion )
56
56
g .P ("// source: " , file .Desc .Path ())
57
57
g .P ()
@@ -68,15 +68,15 @@ func genPath(file *protogen.File, service *protogen.Service, g *protogen.Generat
68
68
if method .Desc .Options ().(* descriptorpb.MethodOptions ).GetDeprecated () {
69
69
continue
70
70
}
71
- pathname := "_GrpcPath " + service .GoName + method .GoName
71
+ pathname := "_CGrpcPath " + service .GoName + method .GoName
72
72
pathurl := "/" + * file .Proto .Package + "." + string (service .Desc .Name ()) + "/" + string (method .Desc .Name ())
73
73
g .P ("var " , pathname , "=" , strconv .Quote (pathurl ))
74
74
}
75
75
g .P ()
76
76
}
77
77
func genServer (file * protogen.File , service * protogen.Service , g * protogen.GeneratedFile ) {
78
78
// Server interface.
79
- serverName := service .GoName + "GrpcServer "
79
+ serverName := service .GoName + "CGrpcServer "
80
80
81
81
g .P ("type " , serverName , " interface {" )
82
82
for _ , method := range service .Methods {
@@ -94,11 +94,11 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
94
94
if method .Desc .Options ().(* descriptorpb.MethodOptions ).GetDeprecated () {
95
95
continue
96
96
}
97
- fname := "func _" + service .GoName + "_" + method .GoName + "_" + "GrpcHandler "
97
+ fname := "func _" + service .GoName + "_" + method .GoName + "_" + "CGrpcHandler "
98
98
p1 := "handler func (" + g .QualifiedGoIdent (contextPackage .Ident ("Context" )) + ",*" + g .QualifiedGoIdent (method .Input .GoIdent ) + ")(*" + g .QualifiedGoIdent (method .Output .GoIdent ) + ",error)"
99
- freturn := g .QualifiedGoIdent (grpcPackage .Ident ("OutsideHandler" ))
99
+ freturn := g .QualifiedGoIdent (cgrpcPackage .Ident ("OutsideHandler" ))
100
100
g .P (fname , "(" , p1 , ")" , freturn , "{" )
101
- g .P ("return func(ctx *" , g .QualifiedGoIdent (grpcPackage .Ident ("Context" )), "){" )
101
+ g .P ("return func(ctx *" , g .QualifiedGoIdent (cgrpcPackage .Ident ("Context" )), "){" )
102
102
g .P ("req:=new(" , g .QualifiedGoIdent (method .Input .GoIdent ), ")" )
103
103
g .P ("if ctx.DecodeReq(req)!=nil{" )
104
104
g .P ("ctx.Abort(" , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
@@ -128,7 +128,7 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
128
128
}
129
129
130
130
//Server Register
131
- g .P ("func Register" , serverName , "(engine *" , g .QualifiedGoIdent (grpcPackage .Ident ("GrpcServer " )), ",svc " , serverName , ",allmids map[string]" , g .QualifiedGoIdent (grpcPackage .Ident ("OutsideHandler" )), "){" )
131
+ g .P ("func Register" , serverName , "(engine *" , g .QualifiedGoIdent (cgrpcPackage .Ident ("CGrpcServer " )), ",svc " , serverName , ",allmids map[string]" , g .QualifiedGoIdent (cgrpcPackage .Ident ("OutsideHandler" )), "){" )
132
132
g .P ("//avoid lint" )
133
133
g .P ("_=allmids" )
134
134
for _ , method := range service .Methods {
@@ -137,10 +137,10 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
137
137
continue
138
138
}
139
139
var mids []string
140
- if proto .HasExtension (mop , pbex .E_GrpcMidwares ) {
141
- mids = proto .GetExtension (mop , pbex .E_GrpcMidwares ).([]string )
140
+ if proto .HasExtension (mop , pbex .E_CgrpcMidwares ) {
141
+ mids = proto .GetExtension (mop , pbex .E_CgrpcMidwares ).([]string )
142
142
}
143
- fname := "_" + service .GoName + "_" + method .GoName + "_" + "GrpcHandler (svc." + method .GoName + ")"
143
+ fname := "_" + service .GoName + "_" + method .GoName + "_" + "CGrpcHandler (svc." + method .GoName + ")"
144
144
if len (mids ) > 0 {
145
145
g .P ("{" )
146
146
str := ""
@@ -150,7 +150,7 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
150
150
}
151
151
str = str [1 :]
152
152
g .P ("requiredMids:=[]string{" , str , "}" )
153
- g .P ("mids:=make([]" , g .QualifiedGoIdent (grpcPackage .Ident ("OutsideHandler" )), ",0," , len (mids )+ 1 , ")" )
153
+ g .P ("mids:=make([]" , g .QualifiedGoIdent (cgrpcPackage .Ident ("OutsideHandler" )), ",0," , len (mids )+ 1 , ")" )
154
154
g .P ("for _,v:=range requiredMids{" )
155
155
g .P ("if mid,ok:=allmids[v];ok{" )
156
156
g .P ("mids = append(mids,mid)" )
@@ -169,7 +169,7 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
169
169
}
170
170
func genClient (file * protogen.File , service * protogen.Service , g * protogen.GeneratedFile ) {
171
171
// Client interface.
172
- clientName := service .GoName + "GrpcClient "
172
+ clientName := service .GoName + "CGrpcClient "
173
173
lowclientName := strings .ToLower (clientName [:1 ]) + clientName [1 :]
174
174
175
175
g .P ("type " , clientName , " interface {" )
@@ -184,9 +184,9 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
184
184
g .P ("}" )
185
185
g .P ()
186
186
g .P ("type " , lowclientName , " struct{" )
187
- g .P ("cc *" , g .QualifiedGoIdent (grpcPackage .Ident ("GrpcClient " )))
187
+ g .P ("cc *" , g .QualifiedGoIdent (cgrpcPackage .Ident ("CGrpcClient " )))
188
188
g .P ("}" )
189
- g .P ("func New" , clientName , "(c *" , g .QualifiedGoIdent (grpcPackage .Ident ("GrpcClient " )), ")(" , clientName , "){" )
189
+ g .P ("func New" , clientName , "(c *" , g .QualifiedGoIdent (cgrpcPackage .Ident ("CGrpcClient " )), ")(" , clientName , "){" )
190
190
g .P ("return &" , lowclientName , "{cc:c}" )
191
191
g .P ("}" )
192
192
g .P ()
@@ -196,7 +196,7 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
196
196
if mop .GetDeprecated () {
197
197
continue
198
198
}
199
- pathname := "_GrpcPath " + service .GoName + method .GoName
199
+ pathname := "_CGrpcPath " + service .GoName + method .GoName
200
200
p1 := "ctx " + g .QualifiedGoIdent (contextPackage .Ident ("Context" ))
201
201
p2 := "req *" + g .QualifiedGoIdent (method .Input .GoIdent )
202
202
freturn := "(*" + g .QualifiedGoIdent (method .Output .GoIdent ) + ",error)"
0 commit comments