Merge pull request #142 from moul/dev/moul/rebase-85

Introducing two new helpers, one for returning in templates go_packag…
This commit is contained in:
Manfred Touron 2019-02-10 22:00:41 +01:00 committed by GitHub
commit c6eca2356c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,6 +160,8 @@ var ProtoHelpersFuncMap = template.FuncMap{
"replaceDict": replaceDict, "replaceDict": replaceDict,
"setStore": setStore, "setStore": setStore,
"getStore": getStore, "getStore": getStore,
"goPkg": goPkg,
"goPkgLastElement": goPkgLastElement,
} }
var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location var pathMap map[interface{}]*descriptor.SourceCodeInfo_Location
@ -1272,3 +1274,13 @@ func replaceDict(src string, dict map[string]interface{}) string {
} }
return src 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]
}