Closed
Description
Take this as an example (in proto3
):
message DeploymentId {
string name = 1;
}
message FlagId {
DeploymentId deployment = 1;
string name = 2;
}
message Flag {
FlagId id = 1;
string value = 2;
string description = 3;
}
service Deployments {
rpc GetFlag (FlagId) returns (Flag) {
option (google.api.http) = {
get: "/deployment/v1/{deployment.name}/flag/{name}"
};
}
}
When I call the service through GET
/deployment/v1/mydeployment/flag/myflag
I get a nil pointer dereference:
2015/07/26 18:58:31 http: panic serving [::1]:59983: runtime error: invalid memory address or nil pointer dereference
goroutine 18 [running]:
net/http.func·011()
/usr/local/Cellar/go/1.4/libexec/src/net/http/server.go:1130 +0xbb
github.com/mwitkow-io/grpc-experiment/proto/deployments.request_Deployments_GetFlag0(0xb5fb88, 0xc2080eda80, 0xb5fc00, 0xc2080363a8, 0xc208032410, 0xc20811a240, 0x0, 0x0, 0x0, 0x0)
/Users/michal/code/mygo/src/github.com/mwitkow-io/grpc-experiment/proto/deployments/deployments.pb.gw.go:46 +0x84b
github.com/mwitkow-io/grpc-experiment/proto/deployments.func·003(0xb60068, 0xc208042780, 0xc208032410, 0xc20811a240)
the Gateway-generated code in question:
func request_Deployments_GetFlag_0(ctx context.Context, client DeploymentsClient, req *http.Request, pathParams map[string]string) (msg proto.Message, err error) {
var protoReq FlagId
var val string
var ok bool
val, ok = pathParams["deployment.name"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "deployment.name")
}
protoReq.Deployment.Name, err = runtime.String(val)
if err != nil {
return nil, err
}
val, ok = pathParams["name"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, err
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Deployments_GetFlag_0); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
return client.GetFlag(ctx, &protoReq)
}
The problem seems to be that the Deployment
field of FlagId
is not initialized and is a nil
reference:
type FlagId struct {
Deployment *DeploymentId `protobuf:"bytes,1,opt,name=deployment" json:"deployment,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
}
I found some complex expressions like {bucket_name=buckets/*} in
parse_test.go`, but I don't think these would help here. @yugui is this a bug or am I just using grpc gateway wrong?