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

Unable to use 'go_package' option with full import path in proto file #65

Open
washanhanzi opened this issue Jan 23, 2021 · 13 comments
Open

Comments

@washanhanzi
Copy link

I am tring to use gripmock with docker, and mount the user.proto file into docker

but the docker exit with:

Starting GripMock
Serving stub admin on http://:4771
sed: /go/src/grpc/user.pb.go: No such file or directory
2021/01/23 03:11:35 Fail on sed

It seems the pb.go file didn't generated.

@Kareem-Emad
Copy link

Kareem-Emad commented Jan 23, 2021

I think the issue happens when you specify the go_package option in your proto file with the full path of your package
example

package service;

option go_package = "internal/grpc/service";

will fail with

sed: /go/src/internal/grpc/repository-service.pb.go: No such file or directory

removing the option or replacing it with just the package name will work

package service;
option go_package = "service";

reproducible example

syntax = "proto3";

package service;

option go_package = "bitbucket-repository-management-service/internal/grpc/service";


//RepositoryService Definition
service RepositoryService {
	rpc add (Repository) returns (AddRepositoryResponse);
}
 
message AddRepositoryResponse {
	Repository addedRepository = 1;
	Error error = 2;
}
message Error {
	string code = 1;
	string message = 2;
}

message Repository {
	int64 id  = 1;
	string name = 2;
	int64 userId = 3;
	bool isPrivate = 4;
}

Run grip-mock with

docker run -p 4770:4770 -p 4771:4771 -v $(pwd):/proto tkpd/gripmock /proto/repository-service.proto

which will give you an error log

Starting GripMock
Serving stub admin on http://:4771
sed: /go/src/grpc/repository-service.pb.go: No such file or directory
2021/01/23 10:53:51 Fail on sed

@washanhanzi
Copy link
Author

Thank you. It fixes my problem.

@Kareem-Emad
Copy link

Kareem-Emad commented Jan 23, 2021

You are welcome

But this is still a valid issue since protoc generator complains about the go package missing the fullpath specification, and it will be required in future release so I think that needs to be supported here.

example with same above file

protoc -I $(pwd) --go_out=plugins=grpc:. $(pwd)/repository-service.proto

will produce warning

WARNING: Deprecated use of 'go_package' option without a full import path in "multi-package/repository-service.proto", please specify:
        option go_package = "multi-package;service";
A future release of protoc-gen-go will require the import path be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.

@washanhanzi washanhanzi changed the title Can't find /go/src/grpc/*.pb.go Unable to use 'go_package' option with full import path in proto file Jan 23, 2021
@benquinteros
Copy link

Any update on this?

@jekiapp
Copy link
Contributor

jekiapp commented Jul 28, 2021

Hi @Kareem-Emad

I'm a bit confused of what is actually being supported in the future. The warning said WARNING: Deprecated use of 'go_package' option without a full import path but the one that fixed the issue is specifying package in the short version. I thought full import path means the longer one.

@jekiapp
Copy link
Contributor

jekiapp commented Jul 30, 2021

It turns out a huge incompatibility change. In order to support this, I need to require go_package for every proto being used, thus it's non-backward compatible.

@jekiapp
Copy link
Contributor

jekiapp commented Aug 2, 2021

I created this PR #83 to solve this issue, it's quite a big change. It will make a backward incompatibility to the old .proto files since it will require go_package declaration.

@jekiapp
Copy link
Contributor

jekiapp commented Aug 3, 2021

I pushed tkpd/gripmock:v1.10 to address this issue, checkout this release

@cchengrbx
Copy link

Hi @jekiapp, thanks for pushing the new release to support go_package. After trying it, I get a pretty cryptic error:

/go/src/grpc/server.go:19:2: package <my_go_package> is not in GOROOT (/usr/local/go/src/<my_go_package>)

Here's how I'm invoking gripmock:

# docker-compose.yml
  my-service:
    container_name: my-service-mock
    image: "tkpd/gripmock:${TAG:-v1.10}"
    networks:
      - sendr
    command: "-stub=/stub /proto/my_api.proto"
    volumes:
      - >-
        ./my-service/proto/:/proto
      - >-
        ./my-service/stub/:/stub
    ports:
      - "4770:4770"
      - "4771:4771"

Any ideas where I went wrong?

@jekiapp
Copy link
Contributor

jekiapp commented Aug 6, 2021

@cchengrbx did you literally put <my_go_package> as value in go_package option?
if yes, then you need to change it to a standard path format. Please check this reference

@cchengrbx
Copy link

No, the go_package is set to something in the format foo/barv1 so nothing special.

@jekiapp
Copy link
Contributor

jekiapp commented Aug 6, 2021 via email

@cchengrbx
Copy link

cchengrbx commented Aug 9, 2021

Thanks @jekiapp, 1.10.1 is working great.

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

5 participants