I am having problem with compiling the .proto file. Looking to generate REST endpoints from the .proto files. Below is the code and error :
syntax = "proto3";
package pb;
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
service UrlShortener {
rpc Hello(HelloRequest) returns (HelloResponse);
rpc Encrypt(EncryptRequest) returns (EncryptResponse);
rpc Decrypt(DecryptRequest) returns (DecryptResponse) {
option (google.api.http) = {
get: "/{hash}"
};
}
}
message HelloRequest {
string Name = 1;
}
message HelloResponse {
string Message = 1;
}
message EncryptRequest {
string OriginalUrl = 1;
}
message EncryptResponse {
UrlMap ResponseMap = 1;
}
message DecryptRequest {
string hash = 1;
}
Error :
github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist.
google/api/annotations.proto: File not found.
urlshortener.proto: Import "google/api/annotations.proto" was not found or had errors.
Please help with fixing this.
I tried : go get -u github.com/grpc-ecosystem/grpc-gateway
But it failed saying : no buildable go source files in path.
I think you have more than one errors in your definition
You are missing the syntax version at the very beginning of your definition:
syntax = "proto3";
There are some undefined types
service.proto:32:3: "UrlMap" is not defined.
service.proto:12:40: "DecryptResponse" is not defined.
You are importing and unused empty.proto
You can use the googleapies from
{GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
Then run using:
protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include -I. service.proto --go_out=plugins=grpc:.
I made the previous changes and it compiles, so I have the service.pb.go file
Edited:
Take a look of this grpc-gateway, maybe can help you
https://github.com/grpc-ecosystem/grpc-gateway
Found out the solution : The problem is that google/api/annotations has moved from the earlier path grpc-ecosystem/grpc-gateway/third_party/googleapis to https://github.com/grpc-ecosystem/grpc-gateway/tree/master/third_party/googleapis/google/api.
Running the following resolved the error : go get -u github.com/grpc-ecosystem/grpc-gateway/...
Related
when I use kitex to start an examples, I Got an error like below
for my step:
mkdir -p Protobuf-test
new file whose name is "echo.proto" and content is like this
syntax = "proto3";
option go_package = "echo";
package echo;
message Request {
string msg = 1;
}
message Response {
string msg = 1;
}
service EchoService {
rpc ClientSideStreaming(stream Request) returns (Response){} // 客户端streaming
rpc ServerSideStreaming(Request) returns (stream Response){} // 服务端streaming
rpc BidiSideStreaming(stream Request) returns (stream Response){} //双向流
}
open a terminal executed a command
kitex -type protobuf -module echoTest -service echoTest echo.proto
please give me some advise, thanks very mush
I take a comparison to using "thrift", it is ok, in the directory "xx/kitex_gen/echo", there has a file named echo.go, but not when using protobuf as model
I'm trying to generate Go file from proto file but it doesn't have json definition in the method's input definition. Should I add the json definition by myself or there were something wrong with my script. Thank you, I sincerely appreciate your help.
Proto file
message RateRequest {
string Base = 1;
string Destination = 2;
}
Generated file
type RateRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
//No json definition here
Base string `protobuf:"bytes,1,opt,name=Base,proto3" json:"Base,omitempty"`
Destination string `protobuf:"bytes,2,opt,name=Destination,proto3" json:"Destination,omitempty"`
}
Protoc script
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
protos/currency.proto
grpcurl
grpcurl --plaintext -d '{Base: "GBP", Destination: "USD"}' localhost:9092 Currency.GetRate
// Error invoking method "Currency.GetRate": error getting request data: message type RateRequest has no known field named base
Since the error is
error getting request data: message type RateRequest has no known field named base
And the json is
json:"Base,omitempty"`
Then it seems it's looking for the wrong field, it should be
json:"base,omitempty"`
I am trying to learn GRPC from the official doc, Here is the tutorial I have followed grpc-go
Generating the proto using this command
protoc --go_out=$PWD helloworld/helloworld.proto
This above command will generate the file helloworld.pb.go without any problem but the problem is the code for the client stub is missing from the generated file
syntax = "proto3";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
The actual error i am getting from the client connection which is
undefined: helloworld.NewGreeterClient
And this has occurred from the line c := pb.NewGreeterClient(conn) in the greeter_client/main.go file
The reason behind because the client stub not generated in the generated file
Issue resolved i have some problems with the command
Here is the actual command
protoc --go_out=plugins=grpc:$PWD helloworld.proto
Add --I to your command. e.g.
protoc -I helloworld --go_out=${PWD} helloworld/*.proto
I am using Ionic, and get the following error:
Runtime Error Uncaught (in promise): Error: Module build failed:
Error: ENOENT: no such file or directory, open
'/Users/richardmarais/Development/ionic/theWhoZoo/src/pages/model/ratingModel.js'
The error is a result of this line of code:
this.ratingModel = new RatingModel();
When I remove this line, I don't get the error.
ratingModel.ts
import { Injectable } from "#angular/core";
import { PersonModel } from './personModel';
import { JobModel } from './jobModel';
#Injectable()
export class RatingModel {
public id: number = null;
public job: JobModel = null;
public review: string = null;
public rating: number = null;
public reviewDate: number = null;
public time: string = null;
public person: PersonModel = null;
public anonymous: number = null;
constructor() {
}
}
Reading other forums, people are getting this error due to the case not matching in their imports, but I have checked mine, and they do match.
import { RatingModel } from '../model/ratingModel';
However, I have noticed something strange in my IDE (Visual Studio Code):
As you can see, in the search results, there are two files for the object, ratingModel.ts and RatingModel.ts. But when I check the actual files system, there is only on file, ratingModel.ts:
Question
Does anyone know what and how to resolve what looks like possibly a bug or fault here?
Thanks
More info:
global packages:
#ionic/cli-utils : 1.0.0
Cordova CLI : 6.4.0
Ionic CLI : 3.0.0
local packages:
#ionic/app-scripts : 1.3.0
#ionic/cli-plugin-cordova : 1.0.0
#ionic/cli-plugin-ionic-angular : 1.0.0
Ionic Framework : ionic-angular 3.2.1
System:
Node : v7.10.0
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : not installed
ios-sim : not installed
Apologies, my bad. I just found another file that was importing the object with the incorrect case. It does appear as if there is no issue, and I had a bug in my code.
import { RatingModel } from '../model/RatingModel';
This error occurred when your component can't be found with your app.module settings.
Follow these steps to solve your problem:
Right click on your web browser and select inspect (in this case I use chrome)
In the source tab, navigate to localhost:8100 (the default port for running ionic)
Go to src -> pages and open corresponded page(in this case 'model')
The name of .ts file and path must be as same as the name and path of the added import path in app.module.ts
In this case, there isn't model/ratingModel.ts
be aware :
The path is case sensitive (maybe the .ts file is RatingModel)
Everything works when I have my proto file defining a service with a streaming response. However when I return a single value, then the generated code is invalid!
Proto File:
syntax = "proto3";
package analyticsServicesGlobal;
option go_package = "generated/analyticsServices";
service HealthCheck {
rpc Health (HealthCheckParam) returns (HealthCheckPayload) {}
}
message HealthCheckPayload {
string message = 1;
}
message HealthCheckParam {
string response = 1;
}
The code generation completes without issue : protoc --go_out=plugins=grpc:$GOPATH/src/gauss minimal.proto
The ide and command line compilation return this error in the generated Go code though:
./minimal.pb.go:130: cannot use handler (type func("gauss/vendor/golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type grpc.UnaryHandler in argument to interceptor
./minimal.pb.go:139: cannot use _HealthCheck_Health_Handler (type func(interface {}, "gauss/vendor/golang.org/x/net/context".Context, func(interface {}) error, grpc.UnaryServerInterceptor) (interface {}, error)) as type grpc.methodHandler in field value
This issue shows up for any service where a non-stream response is returned. I have create this minimal proto file to demonstrate, but every similar service definition has the same issue.
I am on OSX using Go version 1.8.1, protoc version 3.3.0, and the latest protoc plugin for Go go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
I'm sure I'm doing something wrong given the lack of reports on this issue - but I don't see what. Any suggestions are appreciated!