From f78470553bcd80749c16726beb6aab8816a3a7c8 Mon Sep 17 00:00:00 2001 From: Valerio Gheri Date: Mon, 26 Dec 2016 12:13:04 +0100 Subject: [PATCH] Adds helper to know if a field is a repeated one. Closes #32 --- helpers.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/helpers.go b/helpers.go index 201b0c5..b8479ae 100644 --- a/helpers.go +++ b/helpers.go @@ -56,11 +56,12 @@ var ProtoHelpersFuncMap = template.FuncMap{ "kebabCase": func(s string) string { return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1) }, - "getMessageType": getMessageType, - "isFieldMessage": isFieldMessage, - "goType": goType, - "httpVerb": httpVerb, - "httpPath": httpPath, + "getMessageType": getMessageType, + "isFieldMessage": isFieldMessage, + "isFieldRepeated": isFieldRepeated, + "goType": goType, + "httpVerb": httpVerb, + "httpPath": httpPath, } func init() { @@ -89,6 +90,14 @@ func isFieldMessage(f *descriptor.FieldDescriptorProto) bool { 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 { switch *f.Type { case descriptor.FieldDescriptorProto_TYPE_DOUBLE: