Skip to content

Commit 7cea51e

Browse files
committed
update
1 parent d174f21 commit 7cea51e

File tree

21 files changed

+1018
-782
lines changed

21 files changed

+1018
-782
lines changed

cgrpc/protoc-gen-go-cgrpc/cgrpc.go

+118-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package main
22

3-
43
import (
54
"fmt"
65
"strconv"
@@ -34,7 +33,31 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
3433
if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
3534
continue
3635
}
37-
genService(file, service, g)
36+
count := 0
37+
for _, method := range service.Methods {
38+
mop := method.Desc.Options().(*descriptorpb.MethodOptions)
39+
if mop.GetDeprecated() {
40+
continue
41+
}
42+
if !proto.HasExtension(mop, pbex.E_Method) {
43+
continue
44+
}
45+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
46+
need := false
47+
for _, em := range emethod {
48+
if strings.ToUpper(em) == "GRPC" {
49+
need = true
50+
break
51+
}
52+
}
53+
if !need {
54+
continue
55+
}
56+
count++
57+
}
58+
if count > 0 {
59+
genService(file, service, g)
60+
}
3861
}
3962
return g
4063
}
@@ -63,7 +86,22 @@ func genService(file *protogen.File, s *protogen.Service, g *protogen.GeneratedF
6386

6487
func genPath(file *protogen.File, service *protogen.Service, g *protogen.GeneratedFile) {
6588
for _, method := range service.Methods {
66-
if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
89+
mop := method.Desc.Options().(*descriptorpb.MethodOptions)
90+
if mop.GetDeprecated() {
91+
continue
92+
}
93+
if !proto.HasExtension(mop, pbex.E_Method) {
94+
continue
95+
}
96+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
97+
need := false
98+
for _, em := range emethod {
99+
if strings.ToUpper(em) == "GRPC" {
100+
need = true
101+
break
102+
}
103+
}
104+
if !need {
67105
continue
68106
}
69107
pathname := "_CGrpcPath" + service.GoName + method.GoName
@@ -78,7 +116,22 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
78116

79117
g.P("type ", serverName, " interface {")
80118
for _, method := range service.Methods {
81-
if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
119+
mop := method.Desc.Options().(*descriptorpb.MethodOptions)
120+
if mop.GetDeprecated() {
121+
continue
122+
}
123+
if !proto.HasExtension(mop, pbex.E_Method) {
124+
continue
125+
}
126+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
127+
need := false
128+
for _, em := range emethod {
129+
if strings.ToUpper(em) == "GRPC" {
130+
need = true
131+
break
132+
}
133+
}
134+
if !need {
82135
continue
83136
}
84137
g.P(method.Comments.Leading,
@@ -89,10 +142,25 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
89142
g.P()
90143
// Server handler
91144
for _, method := range service.Methods {
92-
pathurl := "/" + *file.Proto.Package + "." + string(service.Desc.Name()) + "/" + string(method.Desc.Name())
93-
if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
145+
mop := method.Desc.Options().(*descriptorpb.MethodOptions)
146+
if mop.GetDeprecated() {
94147
continue
95148
}
149+
if !proto.HasExtension(mop, pbex.E_Method) {
150+
continue
151+
}
152+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
153+
need := false
154+
for _, em := range emethod {
155+
if strings.ToUpper(em) == "GRPC" {
156+
need = true
157+
break
158+
}
159+
}
160+
if !need {
161+
continue
162+
}
163+
pathurl := "/" + *file.Proto.Package + "." + string(service.Desc.Name()) + "/" + string(method.Desc.Name())
96164
fname := "func _" + service.GoName + "_" + method.GoName + "_" + "CGrpcHandler"
97165
p1 := "handler func (" + g.QualifiedGoIdent(contextPackage.Ident("Context")) + ",*" + g.QualifiedGoIdent(method.Input.GoIdent) + ")(*" + g.QualifiedGoIdent(method.Output.GoIdent) + ",error)"
98166
freturn := g.QualifiedGoIdent(cgrpcPackage.Ident("OutsideHandler"))
@@ -135,6 +203,20 @@ func genServer(file *protogen.File, service *protogen.Service, g *protogen.Gener
135203
if mop.GetDeprecated() {
136204
continue
137205
}
206+
if !proto.HasExtension(mop, pbex.E_Method) {
207+
continue
208+
}
209+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
210+
need := false
211+
for _, em := range emethod {
212+
if strings.ToUpper(em) == "GRPC" {
213+
need = true
214+
break
215+
}
216+
}
217+
if !need {
218+
continue
219+
}
138220
var mids []string
139221
if proto.HasExtension(mop, pbex.E_CgrpcMidwares) {
140222
mids = proto.GetExtension(mop, pbex.E_CgrpcMidwares).([]string)
@@ -173,7 +255,22 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
173255

174256
g.P("type ", clientName, " interface {")
175257
for _, method := range service.Methods {
176-
if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
258+
mop := method.Desc.Options().(*descriptorpb.MethodOptions)
259+
if mop.GetDeprecated() {
260+
continue
261+
}
262+
if !proto.HasExtension(mop, pbex.E_Method) {
263+
continue
264+
}
265+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
266+
need := false
267+
for _, em := range emethod {
268+
if strings.ToUpper(em) == "GRPC" {
269+
need = true
270+
break
271+
}
272+
}
273+
if !need {
177274
continue
178275
}
179276
g.P(method.Comments.Leading,
@@ -195,6 +292,20 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
195292
if mop.GetDeprecated() {
196293
continue
197294
}
295+
if !proto.HasExtension(mop, pbex.E_Method) {
296+
continue
297+
}
298+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
299+
need := false
300+
for _, em := range emethod {
301+
if strings.ToUpper(em) == "GRPC" {
302+
need = true
303+
break
304+
}
305+
}
306+
if !need {
307+
continue
308+
}
198309
pathname := "_CGrpcPath" + service.GoName + method.GoName
199310
p1 := "ctx " + g.QualifiedGoIdent(contextPackage.Ident("Context"))
200311
p2 := "req *" + g.QualifiedGoIdent(method.Input.GoIdent)

cgrpc/protoc-gen-go-cgrpc/main.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/chenjie199234/Corelib/internal/version"
910
"github.com/chenjie199234/Corelib/pbex"
1011

1112
"google.golang.org/protobuf/compiler/protogen"
13+
"google.golang.org/protobuf/proto"
1214
"google.golang.org/protobuf/types/descriptorpb"
1315
"google.golang.org/protobuf/types/pluginpb"
1416
)
@@ -39,7 +41,22 @@ func main() {
3941
continue
4042
}
4143
for _, m := range s.Methods {
42-
if m.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
44+
mop := m.Desc.Options().(*descriptorpb.MethodOptions)
45+
if mop.GetDeprecated() {
46+
continue
47+
}
48+
if !proto.HasExtension(mop, pbex.E_Method) {
49+
continue
50+
}
51+
emethod := proto.GetExtension(mop, pbex.E_Method).([]string)
52+
need := false
53+
for _, em := range emethod {
54+
if strings.ToUpper(em) == "GRPC" {
55+
need = true
56+
break
57+
}
58+
}
59+
if !need {
4360
continue
4461
}
4562
if m.Desc.IsStreamingClient() || m.Desc.IsStreamingServer() {

0 commit comments

Comments
 (0)