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:
parent
199050ce6f
commit
c1f10d57e9
33
helpers.go
33
helpers.go
@ -60,16 +60,17 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"kebabCase": func(s string) string {
|
"kebabCase": func(s string) string {
|
||||||
return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
|
return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
|
||||||
},
|
},
|
||||||
"snakeCase": xstrings.ToSnakeCase,
|
"snakeCase": xstrings.ToSnakeCase,
|
||||||
"getMessageType": getMessageType,
|
"getMessageType": getMessageType,
|
||||||
"isFieldMessage": isFieldMessage,
|
"isFieldMessage": isFieldMessage,
|
||||||
"isFieldRepeated": isFieldRepeated,
|
"isFieldRepeated": isFieldRepeated,
|
||||||
"goType": goType,
|
"goType": goType,
|
||||||
"jsType": jsType,
|
"jsType": jsType,
|
||||||
"namespacedFlowType": namespacedFlowType,
|
"namespacedFlowType": namespacedFlowType,
|
||||||
"httpVerb": httpVerb,
|
"httpVerb": httpVerb,
|
||||||
"httpPath": httpPath,
|
"httpPath": httpPath,
|
||||||
"shortType": shortType,
|
"shortType": shortType,
|
||||||
|
"urlHasVarsFromMessage": urlHasVarsFromMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -242,3 +243,15 @@ func httpVerb(m *descriptor.MethodDescriptorProto) string {
|
|||||||
return t.Custom.Kind
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user