Added helper to detect if a url contains variables in the form of url parameters with the same name of the fields of a specific protobuf message

This commit is contained in:
Valerio Gheri 2017-02-01 14:38:14 +01:00
parent 199050ce6f
commit c1f10d57e9

View File

@ -70,6 +70,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
"httpVerb": httpVerb,
"httpPath": httpPath,
"shortType": shortType,
"urlHasVarsFromMessage": urlHasVarsFromMessage,
}
func init() {
@ -242,3 +243,15 @@ func httpVerb(m *descriptor.MethodDescriptorProto) string {
return t.Custom.Kind
}
}
func urlHasVarsFromMessage(path string, d *descriptor.DescriptorProto) bool {
for _, field := range d.Field {
if !isFieldMessage(field) {
if strings.Contains(path, fmt.Sprintf("{%s}", *field.Name)) {
return true
}
}
}
return false
}