From f43d2a2ac8e6b83dd7b109aa851cb052dda25ab6 Mon Sep 17 00:00:00 2001 From: webii Date: Wed, 17 Jan 2018 14:14:39 +0100 Subject: [PATCH] Introducing two new helpers, one for returning in templates go_package path, and second one giving only last element of go_package namespace --- helpers/helpers.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/helpers/helpers.go b/helpers/helpers.go index 3c408fa..2be399c 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -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] +}