Skip to content

Commit

Permalink
fix: that protoc-gen-go-triple cannot generate normally when a proto …
Browse files Browse the repository at this point in the history
…file has multiple services. (#2647)

fixed #2646
  • Loading branch information
r27153733 committed May 16, 2024
1 parent 95370b4 commit fca0a3a
Show file tree
Hide file tree
Showing 10 changed files with 4,219 additions and 14 deletions.
17 changes: 10 additions & 7 deletions cmd/protoc-gen-go-triple/gen/generator/tripleTpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ const TypeCheckTpl = `var ({{$t := .}}{{range $s := .Services}}
`

const InterfaceTpl = `// {{$t := .}}{{range $s := .Services}}{{.ServiceName}} is a client for the {{$t.ProtoPackage}}.{{$s.ServiceName}} service.
const InterfaceTpl = `{{$t := .}}{{range $s := .Services}}
// {{.ServiceName}} is a client for the {{$t.ProtoPackage}}.{{$s.ServiceName}} service.
type {{$s.ServiceName}} interface { {{- range $s.Methods}}
{{upper .MethodName}}(ctx context.Context{{if .StreamsRequest}}{{else}}, req *{{.RequestType}}{{end}}, opts ...client.CallOption) {{if or .StreamsReturn .StreamsRequest}}({{$s.ServiceName}}_{{.MethodName}}Client, error){{else}}(*{{.ReturnType}}, error){{end}}{{end}}
}{{end}}
Expand All @@ -208,7 +209,7 @@ func New{{.ServiceName}}(cli *client.Client, opts ...client.ReferenceOption) ({{
}, nil
}
func SetConsumerService(srv common.RPCService) {
func SetConsumer{{.ServiceName}}(srv common.RPCService) {
dubbo.SetConsumerServiceWithInfo(srv,&{{.ServiceName}}_ClientInfo)
}
Expand Down Expand Up @@ -346,18 +347,19 @@ func (cli *{{$s.ServiceName}}{{.MethodName}}Client) Conn() (triple_protocol.Stre
`

const MethodInfoTpl = `{{$t := .}}{{range $i, $s := .Services}}var {{.ServiceName}}_ClientInfo = client.ClientInfo{
const MethodInfoTpl = `{{$t := .}}{{range $i, $s := .Services}}
var {{.ServiceName}}_ClientInfo = client.ClientInfo{
InterfaceName: "{{$t.ProtoPackage}}.{{.ServiceName}}",
MethodNames: []string{ {{- range $j, $m := .Methods}}"{{.MethodName}}"{{if last $j (len $s.Methods)}}{{else}},{{end}}{{end -}} },
ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
dubboCli := dubboCliRaw.(*{{$s.ServiceName}}Impl)
dubboCli.conn = conn
},
}{{end}}
`

const HandlerTpl = `{{$t := .}}{{range $s := .Services}}// {{.ServiceName}}Handler is an implementation of the {{$t.ProtoPackage}}.{{.ServiceName}} service.
const HandlerTpl = `{{$t := .}}{{range $s := .Services}}
// {{.ServiceName}}Handler is an implementation of the {{$t.ProtoPackage}}.{{.ServiceName}} service.
type {{.ServiceName}}Handler interface { {{- range $s.Methods}}
{{upper .MethodName}}(context.Context, {{if .StreamsRequest}}{{$s.ServiceName}}_{{.MethodName}}Server{{else}}*{{.RequestType}}{{if .StreamsReturn}}, {{$s.ServiceName}}_{{.MethodName}}Server{{end}}{{end}}) {{if .StreamsReturn}}error{{else}}(*{{.ReturnType}}, error){{end}}{{end}}
}
Expand All @@ -366,7 +368,7 @@ func Register{{.ServiceName}}Handler(srv *server.Server, hdlr {{.ServiceName}}Ha
return srv.Register(hdlr, &{{.ServiceName}}_ServiceInfo, opts...)
}
func SetProviderService(srv common.RPCService) {
func SetProvider{{.ServiceName}}(srv common.RPCService) {
dubbo.SetProviderServiceWithInfo(srv,&{{.ServiceName}}_ServiceInfo)
}{{end}}
`
Expand Down Expand Up @@ -443,7 +445,8 @@ func (g *{{$s.ServiceName}}{{.MethodName}}Server) Send(msg *{{.ReturnType}}) err
{{end}}{{end}}{{end}}{{end}}
`

const ServiceInfoTpl = `{{$t := .}}{{range $s := .Services}}var {{.ServiceName}}_ServiceInfo = server.ServiceInfo{
const ServiceInfoTpl = `{{$t := .}}{{range $s := .Services}}
var {{.ServiceName}}_ServiceInfo = server.ServiceInfo{
InterfaceName: "{{$t.ProtoPackage}}.{{.ServiceName}}",
ServiceType: (*{{.ServiceName}}Handler)(nil),
Methods: []server.MethodInfo{ {{- range .Methods}}{{if .StreamsRequest}}{{if .StreamsReturn}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-triple/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module dubbo.apache.org/dubbo-go/v3/cmd/protoc-gen-go-triple
go 1.20

require (
github.com/golang/protobuf v1.5.3
github.com/golang/protobuf v1.5.4
github.com/pkg/errors v0.9.1
google.golang.org/protobuf v1.33.0
)
Expand Down
8 changes: 2 additions & 6 deletions cmd/protoc-gen-go-triple/go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
38 changes: 38 additions & 0 deletions cmd/protoc-gen-go-triple/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

go build

for dir in ./test/correctly/*/; do
cd "$dir" || exit 1

dir_name=$(basename "$dir")

protoc --go_out=. --go_opt=paths=source_relative --plugin=protoc-gen-go-triple=../../../protoc-gen-go-triple --go-triple_out=. ./proto/greet.proto
go mod tidy

go vet ./proto/*.go
result=$?

if [ $result -ne 0 ]; then
echo "go vet found issues in $dir_name."
exit $result
fi

echo "No issues found in $dir_name."
cd - || exit 1
done
76 changes: 76 additions & 0 deletions cmd/protoc-gen-go-triple/test/correctly/multiple_services/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module multiple_service

require (
dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029
github.com/golang/protobuf v1.5.4
google.golang.org/protobuf v1.33.0
)

require (
github.com/RoaringBitmap/roaring v1.2.3 // indirect
github.com/Workiva/go-datastructures v1.0.52 // indirect
github.com/apache/dubbo-getty v1.4.9 // indirect
github.com/apache/dubbo-go-hessian2 v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/creasty/defaults v1.5.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dubbogo/gost v1.14.0 // indirect
github.com/dubbogo/grpc-go v1.42.10 // indirect
github.com/dubbogo/triple v1.2.2-rc3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/influxdata/tdigest v0.0.1 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/k0kubun/pp v3.0.1+incompatible // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.10.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/grpc v1.52.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.22
Loading

0 comments on commit fca0a3a

Please sign in to comment.