Adds helper to know if a field is a repeated one. Closes #32

This commit is contained in:
Valerio Gheri 2016-12-26 12:13:04 +01:00
parent c26d72d1ad
commit f78470553b

View File

@ -58,6 +58,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
}, },
"getMessageType": getMessageType, "getMessageType": getMessageType,
"isFieldMessage": isFieldMessage, "isFieldMessage": isFieldMessage,
"isFieldRepeated": isFieldRepeated,
"goType": goType, "goType": goType,
"httpVerb": httpVerb, "httpVerb": httpVerb,
"httpPath": httpPath, "httpPath": httpPath,
@ -89,6 +90,14 @@ func isFieldMessage(f *descriptor.FieldDescriptorProto) bool {
return false return false
} }
func isFieldRepeated(f *descriptor.FieldDescriptorProto) bool {
if f.Type != nil && f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED {
return true
}
return false
}
func goType(pkg string, f *descriptor.FieldDescriptorProto) string { func goType(pkg string, f *descriptor.FieldDescriptorProto) string {
switch *f.Type { switch *f.Type {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE: case descriptor.FieldDescriptorProto_TYPE_DOUBLE: