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
437 stars 70 forks source link

Panic: can't evaluate field GoPkg in type *descriptor.File #128

Open piotrekmonko opened 5 years ago

piotrekmonko commented 5 years ago

Following example in examples/single-package-mode/templates/service.go.tmpl leads to a panic:

Template:

{{$currentFile := $file.Name | getProtoFile}}

{{- range .Service.Method}}
{{- $in := .InputType | getMessageType $file}}
{{- $out := .OutputType | getMessageType $file}}
{{$in.GoType $currentFile.GoPkg.Path}}                <-- panics
{{- end}} {{/*range **Method*/}}

Output:

panic: template: rpc.go.tmpl:50:34: executing "rpc.go.tmpl" at <$currentFile.GoPkg.P...>: can't evaluate field GoPkg in type *descriptor.File

goroutine 1 [running]:
main.(*GenericTemplateBasedEncoder).Files(0xc00009d8b0, 0x14, 0xc000029180, 0xc000184000)
    ~/go/src/moul.io/protoc-gen-gotemplate/encoder.go:213 +0x4df
main.main()
    ~/go/src/moul.io/protoc-gen-gotemplate/main.go:130 +0x411
--gotemplate_out: protoc-gen-gotemplate: Plugin failed with status code 2.

Has the return type of getProtoFile changed? Or is there an error in the template?

zachfi commented 4 years ago

I think this is where you want to look for the methods available. https://godoc.org/google.golang.org/protobuf/types/descriptorpb