Introducing two new helpers, one for returning in templates go_package path, and second one giving only last element of go_package namespace

This commit is contained in:
webii 2018-01-17 14:14:39 +01:00 committed by Manfred Touron
parent baffaa4b6a
commit f43d2a2ac8
No known key found for this signature in database
GPG Key ID: 6D4DED2EAB123456

View File

@ -160,6 +160,8 @@ var ProtoHelpersFuncMap = template.FuncMap{
"replaceDict": replaceDict,
"setStore": setStore,
"getStore": getStore,
"goPkg": goPkg,
"goPkgLastElement": goPkgLastElement,
}
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
@ -1272,3 +1274,13 @@ func replaceDict(src string, dict map[string]interface{}) string {
}
return src
}
func goPkg(f *descriptor.FileDescriptorProto) string {
return f.Options.GetGoPackage()
}
func goPkgLastElement(f *descriptor.FileDescriptorProto) string {
pkg := goPkg(f)
pkgSplitted := strings.Split(pkg, "/")
return pkgSplitted[len(pkgSplitted)-1]
}