add helper like httpPath for get path in additional bindings options

This commit is contained in:
Thomas KERAMBLOCH 2018-02-13 15:57:07 +01:00
parent 15ac366c8d
commit 0c29a9922f

View File

@ -101,36 +101,37 @@ var ProtoHelpersFuncMap = template.FuncMap{
} }
return slice.Index(int(i)).Interface() return slice.Index(int(i)).Interface()
}, },
"snakeCase": xstrings.ToSnakeCase, "snakeCase": xstrings.ToSnakeCase,
"getProtoFile": getProtoFile, "getProtoFile": getProtoFile,
"getMessageType": getMessageType, "getMessageType": getMessageType,
"getEnumValue": getEnumValue, "getEnumValue": getEnumValue,
"isFieldMessage": isFieldMessage, "isFieldMessage": isFieldMessage,
"isFieldMessageTimeStamp": isFieldMessageTimeStamp, "isFieldMessageTimeStamp": isFieldMessageTimeStamp,
"isFieldRepeated": isFieldRepeated, "isFieldRepeated": isFieldRepeated,
"haskellType": haskellType, "haskellType": haskellType,
"goType": goType, "goType": goType,
"goZeroValue": goZeroValue, "goZeroValue": goZeroValue,
"goTypeWithPackage": goTypeWithPackage, "goTypeWithPackage": goTypeWithPackage,
"jsType": jsType, "jsType": jsType,
"jsSuffixReserved": jsSuffixReservedKeyword, "jsSuffixReserved": jsSuffixReservedKeyword,
"namespacedFlowType": namespacedFlowType, "namespacedFlowType": namespacedFlowType,
"httpVerb": httpVerb, "httpVerb": httpVerb,
"httpPath": httpPath, "httpPath": httpPath,
"httpBody": httpBody, "httpPathsAdditionalBindings": httpPathsAdditionalBindings,
"shortType": shortType, "httpBody": httpBody,
"urlHasVarsFromMessage": urlHasVarsFromMessage, "shortType": shortType,
"lowerGoNormalize": lowerGoNormalize, "urlHasVarsFromMessage": urlHasVarsFromMessage,
"goNormalize": goNormalize, "lowerGoNormalize": lowerGoNormalize,
"leadingComment": leadingComment, "goNormalize": goNormalize,
"trailingComment": trailingComment, "leadingComment": leadingComment,
"leadingDetachedComments": leadingDetachedComments, "trailingComment": trailingComment,
"stringFieldExtension": stringFieldExtension, "leadingDetachedComments": leadingDetachedComments,
"boolFieldExtension": boolFieldExtension, "stringFieldExtension": stringFieldExtension,
"isFieldMap": isFieldMap, "boolFieldExtension": boolFieldExtension,
"fieldMapKeyType": fieldMapKeyType, "isFieldMap": isFieldMap,
"fieldMapValueType": fieldMapValueType, "fieldMapKeyType": fieldMapKeyType,
"replaceDict": replaceDict, "fieldMapValueType": fieldMapValueType,
"replaceDict": replaceDict,
} }
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
@ -726,6 +727,40 @@ func httpPath(m *descriptor.MethodDescriptorProto) string {
} }
} }
func httpPathsAdditionalBindings(m *descriptor.MethodDescriptorProto) []string {
ext, err := proto.GetExtension(m.Options, options.E_Http)
if err != nil {
panic(err.Error())
}
opts, ok := ext.(*options.HttpRule)
if !ok {
panic(fmt.Sprintf("extension is %T; want an HttpRule", ext))
}
var httpPaths []string
var optsAdditionalBindings = opts.GetAdditionalBindings()
for _, optAdditionalBindings := range optsAdditionalBindings {
switch t := optAdditionalBindings.Pattern.(type) {
case *options.HttpRule_Get:
httpPaths = append(httpPaths, t.Get)
case *options.HttpRule_Post:
httpPaths = append(httpPaths, t.Post)
case *options.HttpRule_Put:
httpPaths = append(httpPaths, t.Put)
case *options.HttpRule_Delete:
httpPaths = append(httpPaths, t.Delete)
case *options.HttpRule_Patch:
httpPaths = append(httpPaths, t.Patch)
case *options.HttpRule_Custom:
httpPaths = append(httpPaths, t.Custom.Path)
default:
// nothing
}
}
return httpPaths
}
func httpVerb(m *descriptor.MethodDescriptorProto) string { func httpVerb(m *descriptor.MethodDescriptorProto) string {
ext, err := proto.GetExtension(m.Options, options.E_Http) ext, err := proto.GetExtension(m.Options, options.E_Http)