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

add new helpers #83

Closed pmoroney closed 6 years ago

pmoroney commented 6 years ago

I have added quite a few helpers that I have used for documentation and client library generation.

goZeroValue: returns the Go zero value for a field.

leadingComment, trailingComment, leadingDetachedComments: returns the comments in the protobuf file near the item.

stringFieldExtension, boolFieldExtension: returns either a string or a bool field extension in the protobuf file when given the extension id.

isFieldMap, fieldMapKeyType, fieldMapValueType: functions to figure out if a field is a map and what types are the keys and values.

replaceDict: does a replace for every string in a sprig dictionary.

weitzj commented 6 years ago

Thank you so much. I am really looking forward to this

weitzj commented 6 years ago

Love it!

i.e. (working example): "add a multiline Golang code-comment in front of my Service:

//{{regexSplit "\n" (trimSuffix "\n" (.service | leadingComment)) -1 | join "\n//"}}

Idea: