Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid import during code generation #337

Closed
sagikazarmark opened this issue Mar 25, 2017 · 3 comments
Closed

Invalid import during code generation #337

sagikazarmark opened this issue Mar 25, 2017 · 3 comments

Comments

@sagikazarmark
Copy link

I would like to use gRPC Gateway, because it looks incredibly awesome, but I encountered the following problem and I haven't been able to solve it so far:

When trying to use Google's http annotations, the generated pb.go file looks a bit strange. It includes the following:

import _ "google/api"

I have to admit that I don't use protoc as it is described in the README, but I think it should work this way too. Furthermore, I've tried every combination of import paths, none of them worked.

I use multiple paths in my GOPATH variable: there is one for package installations (the first) and the other where my code lives. Something like this: $HOME/.go:$HOME/Projects/go

Also, my protoc binary is copied to my own binary prefix. I know that it might not found certain files that way, but I provide an import path for the protobuf protos.

I use Glide for vendoring.

So my actual command is:
protoc -I ${PROTO_PATH} -I vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I vendor/github.com/google/protobuf/src ${PROTO_PATH}/iam/user/v1alpha1/login.proto --go_out=plugins=grpc:apis

As you can see, I add googleapis and protobuf as import path (besides the one where my actual proto file lives).

My proto looks like this:

import "google/api/annotations.proto";

...

service MyService {
    rpc Action (Request) returns (Response){
        option (google.api.http) = { get: "/action" };
    }
}

I believe it should work this way, but it generates a file with the above import. Looking at the examples in this repository I see imports like this:

import _ "google.golang.org/genproto/googleapis/api/annotations"

I'm a little bit confused, because I don't understand how the go protoc plugin guesses where it should look for the generated file of a proto.

Any help would be appreciated, thank you very much in advance.

@sagikazarmark
Copy link
Author

sagikazarmark commented Mar 25, 2017

Okay, I realized I was using the deprecated way of googleapis import instead of github.com/googleapis/googleapis. This looks like problem solved.

@tmc
Copy link
Collaborator

tmc commented Mar 27, 2017

@sagikazarmark can you clarify further here for anyone that might run into the same thing?

@tmc tmc closed this as completed Mar 27, 2017
@sagikazarmark
Copy link
Author

I added the "old" googleapis import path from this repo to the protoc command: -I vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis

Adding the official googleapis repo as a dependency solved the problem. See the solution here.

@tamalsaha tamalsaha mentioned this issue Mar 30, 2017
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants