Closed
Description
Input proto:
syntax = "proto3";
package foo;
import "google/api/annotations.proto";
service EchoService {
rpc echo(EchoRequest) returns (EchoResponse) {
option (google.api.http) = {
get: "/{msg}"
additional_bindings: {
get: "/"
};
};
}
}
message EchoRequest {
string msg = 1;
}
message EchoResponse {
string msg = 2;
}
This is for sending a message optionally, but it seems grpc-gateway doesn't accept the path like this? protoc fails with the following error:
--grpc-gateway_out: segment neither wildcards, literal or variable: expected "{" but got "\x00": /
An empty string (get: ""
) goes into the panic:
panic: reflect: indirection through nil pointer to embedded struct [recovered]
panic: reflect: indirection through nil pointer to embedded struct
goroutine 1 [running]:
text/template.errRecover(0xc4200e57c8)
/usr/lib/google-golang/src/text/template/exec.go:146 +0x62
panic(0x5bc500, 0xc4201dde30)
/usr/lib/google-golang/src/runtime/panic.go:489 +0x2e1
reflect.Value.FieldByIndex(0x5e1fa0, 0x0, 0x19, 0xc4201dde20, 0x2, 0x2, 0x0, 0x702a80, 0x5effa0)
/usr/lib/google-golang/src/reflect/value.go:798 +0x20c
text/template.(*state).evalField(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0xc4200ea081, 0x6, 0x6ffa80, 0xc4200dc390, 0x0, 0x0, ...)
/usr/lib/google-golang/src/text/template/exec.go:569 +0xaef
text/template.(*state).evalFieldChain(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0x5e1fa0, 0x0, 0x19, 0x6ffa80, 0xc4200dc390, 0xc4200ea0a0, ...)
/usr/lib/google-golang/src/text/template/exec.go:523 +0x128
text/template.(*state).evalFieldNode(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0xc4200dc390, 0xc4200e4ff8, 0x1, 0x1, 0x0, 0x0, ...)
/usr/lib/google-golang/src/text/template/exec.go:490 +0x118
text/template.(*state).evalArg(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0x702a80, 0x607200, 0x6ffa80, 0xc4200dc390, 0x2, 0xc4200e5138, ...)
/usr/lib/google-golang/src/text/template/exec.go:742 +0xf4e
text/template.(*state).evalCall(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0x5c86e0, 0x617f90, 0x13, 0x6ff9c0, 0xc4200dc300, 0x6152e5, ...)
/usr/lib/google-golang/src/text/template/exec.go:643 +0x279
text/template.(*state).evalFunction(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0xc4200dc330, 0x6ff9c0, 0xc4200dc300, 0xc4200e8200, 0x3, 0x4, ...)
/usr/lib/google-golang/src/text/template/exec.go:536 +0x18e
text/template.(*state).evalCommand(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0xc4200dc300, 0x0, 0x0, 0x0, 0x5, 0x3, ...)
/usr/lib/google-golang/src/text/template/exec.go:433 +0x6cd
text/template.(*state).evalPipeline(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0xc4200da0f0, 0xc4200dc4e0, 0xc4201dd808, 0x519)
/usr/lib/google-golang/src/text/template/exec.go:406 +0xf2
text/template.(*state).walkIfOrWith(0xc4200e5748, 0xa, 0x5e1fa0, 0x0, 0x19, 0xc4200da0f0, 0xc4200dc420, 0xc4200dc4e0)
/usr/lib/google-golang/src/text/template/exec.go:261 +0xbc
text/template.(*state).walk(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0x6ffb40, 0xc420016900)
/usr/lib/google-golang/src/text/template/exec.go:237 +0x377
text/template.(*state).walk(0xc4200e5748, 0x5e1fa0, 0x0, 0x19, 0x6ffba0, 0xc4200dc2a0)
/usr/lib/google-golang/src/text/template/exec.go:240 +0x139
text/template.(*Template).execute(0xc4200e8100, 0x6fc4e0, 0xc4201db570, 0x5e1fa0, 0x0, 0x0, 0x0)
/usr/lib/google-golang/src/text/template/exec.go:195 +0x20a
text/template.(*Template).Execute(0xc4200e8100, 0x6fc4e0, 0xc4201db570, 0x5e1fa0, 0x0, 0x0, 0x0)
/usr/lib/google-golang/src/text/template/exec.go:178 +0x53
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway.applyTemplate(0xc420107700, 0xc4201bc600, 0xa, 0x10, 0x0, 0xc4201bc600, 0x8, 0x10, 0x0)
/usr/local/google/home/mukai/gopath/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/template.go:89 +0x3f8
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway.(*generator).generate(0xc420167500, 0xc420107700, 0xd, 0xc4200e5d38, 0x1, 0x1)
/usr/local/google/home/mukai/gopath/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go:111 +0x7ed
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway.(*generator).Generate(0xc420167500, 0xc4200ae448, 0x1, 0x1, 0x1, 0xc4200ae448, 0x0, 0x1, 0x10)
/usr/local/google/home/mukai/gopath/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/generator.go:67 +0x17c
main.main()
/usr/local/google/home/mukai/gopath/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/main.go:96 +0x7a6
--grpc-gateway_out: protoc-gen-grpc-gateway: Plugin failed with status code 2.
Apparently the workaround is to specify the path prefix (like /echo/{msg}
and /echo
) or setting a special token for the default value (like /{msg}
vs /_
) -- but is it possible to allow the path like this?