tpl: Misco GoDoc improvements

This commit is contained in:
Bjørn Erik Pedersen
2022-11-29 11:38:21 +01:00
parent dc44bca963
commit 7d5e3ab8a8
3 changed files with 20 additions and 3 deletions

View File

@@ -141,6 +141,22 @@ func (t goDocFunc) toJSON() ([]byte, error) {
return buf.Bytes(), nil
}
// ToMap returns a limited map representation of the namespaces.
func (namespaces TemplateFuncsNamespaces) ToMap() map[string]any {
m := make(map[string]any)
for _, ns := range namespaces {
mm := make(map[string]any)
for name, mapping := range ns.MethodMappings {
mm[name] = map[string]any{
"Examples": mapping.Examples,
"Aliases": mapping.Aliases,
}
}
m[ns.Name] = mm
}
return m
}
// MarshalJSON returns the JSON encoding of namespaces.
func (namespaces TemplateFuncsNamespaces) MarshalJSON() ([]byte, error) {
var buf bytes.Buffer