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

Error to build project with go module #846

Closed
4 tasks done
nlamirault opened this issue Jan 9, 2019 · 3 comments
Closed
4 tasks done

Error to build project with go module #846

nlamirault opened this issue Jan 9, 2019 · 3 comments

Comments

@nlamirault
Copy link

The gRPC-Gateway project is maintained by volunteers in their spare time. Please follow these troubleshooting steps before submitting an issue.

  • Check if your issue has already been reported (https://github.com/grpc-ecosystem/grpc-gateway/issues).
  • Update your protoc to the latest version.
  • Update your copy of the grpc-gateway library to the latest version from github:
    go get -u github.com/grpc-ecosystem/grpc-gateway
  • Delete the protoc-gen-grpc-gateway and protoc-gen-swagger binary from your PATH,
    and reinstall the latest versions:
    go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
    go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

I install binaries like that :

$ go get -u github.com/golang/protobuf/[email protected]
$ go get -u github.com/golang/protobuf/[email protected]
$ go get -u github.com/grpc-ecosystem/grpc-gateway/[email protected]
$ go get -u github.com/grpc-ecosystem/grpc-gateway/[email protected]

I still have a problem!

I generate go files from protobuf.

syntax="proto3";

package info;

// for grpc-gateway
import "google/api/annotations.proto";

message GetInfoRequest {
}

message GetInfoResponse {
  string version = 1;
  repeated WebServiceStatus webservices = 2;
}

message WebServiceStatus {
  string endpoint = 1;
  string name = 2;
  string status = 3;
  string text = 4;
}

service InfoService {
  rpc Get(GetInfoRequest) returns (GetInfoResponse) {
    option (google.api.http) = {
      get : "/info"
    };
  }
}

When i try to compile i've got this error :

pb/info/info.pb.gw.go:82:39: not enough arguments in call to runtime.AnnotateContext
        have ("context".Context, *http.Request)
        want ("context".Context, *runtime.ServeMux, *http.Request)
pb/info/info.pb.gw.go:84:21: not enough arguments in call to runtime.HTTPError
        have ("context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
        want ("context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
pb/info/info.pb.gw.go:89:21: not enough arguments in call to runtime.HTTPError
        have ("context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
        want ("context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, error)
pb/info/info.pb.gw.go:93:28: not enough arguments in call to forward_InfoService_Get_0
        have ("context".Context, runtime.Marshaler, http.ResponseWriter, *http.Request, proto.Message, []func("context".Context, http.ResponseWriter, proto.Message) error...)
        want ("context".Context, *runtime.ServeMux, runtime.Marshaler, http.ResponseWriter, *http.Request, proto.Message, ...func("context".Context, http.ResponseWriter, proto.Message) error)

In the go.mod file i've got :

$ rg proto go.mod 
59:     github.com/golang/protobuf v1.2.0
168:    google.golang.org/genproto v0.0.0-20190108161440-ae2f86662275
$ rg grpc go.mod 
70:     github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
71:     github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
72:     github.com/grpc-ecosystem/grpc-gateway v1.6.4
157:    github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
169:    google.golang.org/grpc v1.17.0

Any idea how fix that ? Is it an error from versions ?

Thanks.

@johanbrandhorst
Copy link
Collaborator

This implies a version difference between the generator and the runtime library. Are you using vendor to make sure that the generator version is the correct version? your go mod file looks fine, but if you look at the 1.6.4 tree the runtime has the new methods, so it looks like you're using an old generator?

@nlamirault
Copy link
Author

I try to vendoring using :

go mod edit -require github.com/grpc-ecosystem/grpc-gateway/[email protected]

but i've got this error :

$ go mod tidy
go: finding github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway v1.6.4
go: github.com/grpc-ecosystem/grpc-gateway/[email protected]: unknown revision protoc-gen-grpc-gateway/v1.6.4
go: error loading module requirements

So i've install using go get -u github.com/grpc-ecosystem/grpc-gateway/[email protected].

I've got a shell script which generate files :

#!/usr/bin/env bash

# generate the gRPC code

function generate_grpcgw {
    pushd $1
    echo "> Generate gRPC for $1"
    rm -rf *.pb.go
    protoc -I /usr/local/include -I . -I ../../vendor -I ../googleapis \
       --go_out=plugins=grpc:. *.proto
    rm -rf *.pb.gw.go

    echo "> Generate gRPC Gateway for $1"
    protoc -I /usr/local/include -I . -I ../../vendor -I ../googleapis \
       --grpc-gateway_out=logtostderr=true:. *.proto

    echo "> Generate Swagger for $1"
    rm -rf ../swagger/*.swagger.json
    protoc -I /usr/local/include -I . -I ../../vendor -I ../googleapis \
       --swagger_out=logtostderr=true:. *.proto
    popd
}

function generate_grpc {
    pushd $1
    echo "> Generate gRPC for $1"
    rm -rf *.pb.go
    protoc -I /usr/local/include -I . -I ../../vendor -I ../googleapis \
        --go_out=plugins=grpc:. *.proto
    popd
}

function generate_swagger {
    echo "> Generate Swagger"
    find . -name "*.json" | xargs -I '{}' mv '{}' swagger/
    rm -f swagger/api.swagger.json
    go run ./swagger/swagger.go swagger > swagger/api.swagger.json
}

generate_grpcgw v1
generate_grpc health
generate_grpc info

generate_swagger

@johanbrandhorst
Copy link
Collaborator

Well, the only thing I can think of is if you have an old installation of protoc-gen-grpc-gateway in your $PATH somewhere. Make sure the version you're go geting is the one you're also running.

Also, I doubt this is an issue with this repo so I'm going to close it. Please join the #grpc-gateway channel of the gophers slack if you need continue assistance. See https://github.com/grpc-ecosystem/grpc-gateway/blob/master/ISSUE_TEMPLATE.md#i-still-have-a-problem for more details on how to go there.

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