From 8e20c64bcdf44b3d38df5b9209f351bfdada55b5 Mon Sep 17 00:00:00 2001 From: Li Peng Date: Wed, 4 Sep 2019 21:45:49 -0700 Subject: [PATCH 1/2] support common google apis and fix issue with certain package names small fix --- Dockerfile | 1 + gripmock.go | 5 ++++- protoc-gen-gripmock/generator.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3d2682d3..e33e930f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN mkdir /stubs RUN apk -U --no-cache add git protobuf RUN go get -u -v github.com/golang/protobuf/protoc-gen-go \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \ github.com/mitchellh/mapstructure \ google.golang.org/grpc \ google.golang.org/grpc/reflection \ diff --git a/gripmock.go b/gripmock.go index 6aaf49fb..9fd0ce0b 100644 --- a/gripmock.go +++ b/gripmock.go @@ -102,10 +102,13 @@ func generateProtoc(param protocParam) { if len(protodirs) > 0 { protodir = strings.Join(protodirs[:len(protodirs)-1], "/") + "/" } - args := []string{"-I", protodir} // include well-known-types args = append(args, "-I", "/protobuf") + if os.Getenv("GOPATH") != "" { + googlesApisPath := os.Getenv("GOPATH")+"/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/" + args = append(args, "-I", googlesApisPath) + } args = append(args, param.protoPath...) args = append(args, "--go_out=plugins=grpc:"+param.output) args = append(args, fmt.Sprintf("--gripmock_out=admin-port=%s,grpc-address=%s,grpc-port=%s:%s", diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 01c70c34..dcc3b3dd 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -169,6 +169,10 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st continue } + // some package declarations use a semicolon, which causes a formatting error + // ignore for now + pkg = strings.Split(pkg, ";")[0] + alias := getAlias(proto.GetName()) // in case of found same alias if ok := aliases[alias]; ok { From 40b7584bc3010fd96e8d8476b5372bd9c47a3d86 Mon Sep 17 00:00:00 2001 From: Li Peng Date: Thu, 5 Sep 2019 23:40:04 -0700 Subject: [PATCH 2/2] use alis --- protoc-gen-gripmock/generator.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index dcc3b3dd..37e68465 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -170,8 +170,11 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st } // some package declarations use a semicolon, which causes a formatting error - // ignore for now - pkg = strings.Split(pkg, ";")[0] + // use the alias instead, if available + var sections = strings.Split(pkg, ";") + if len(sections) > 1 { + pkg = sections[1] + } alias := getAlias(proto.GetName()) // in case of found same alias