moul / protoc-gen-gotemplate

:open_file_folder: generic protocol generator based on golang's text/template (grpc/protobuf)
https://manfred.life/protoc-gen-gotemplate
MIT License
438 stars 68 forks source link

Fix error on use pipeline after splitArray result #78

Closed shiwano closed 6 years ago

shiwano commented 6 years ago

Hi team,

I tried to use go-kit templates, but I got templating error like the below.

cd pb; protoc --gotemplate_out=destination_dir=../gen,template_dir=../templates/{{.File.Package}}/gen:../gen ./echo.proto
panic: template: grpc.go.tmpl:60:97: executing "grpc.go.tmpl" at <last>: wrong type for value; expected []interface {}; got []string

goroutine 1 [running]:
main.(*GenericTemplateBasedEncoder).Files(0xc42008b860, 0x22, 0xc420061080, 0xc420170000)
        /Users/shiwano/code/src/github.com/moul/protoc-gen-gotemplate/encoder.go:194 +0x520
main.main()
        /Users/shiwano/code/src/github.com/moul/protoc-gen-gotemplate/main.go:130 +0x402
--gotemplate_out: protoc-gen-gotemplate: Plugin failed with status code 2.

This error can be reproduced on http://protoc-gen-gotemplate.m.42.am/ with code the below.

syntax = "proto3";
package echo;
option go_package = "echopb";
service EchoService {
  rpc Echo(EchoMessage) returns (EchoMessage) {}
}
message EchoMessage {
  string message = 1;
}
{{- range .Service.Method}}
{{.InputType | splitArray "." | last}}
{{- end}}

It seems like that an error occurs by using pipeline after []string. It resolved by that splitArray helper returns []interface{} instead of []string. Cound you review it?

Thanks.