1
0
Fork 0
mirror of https://github.com/Luzifer/korvike.git synced 2024-11-08 23:40:05 +00:00
korvike/functions/collect.go

30 lines
716 B
Go

package functions
import (
"errors"
"sync"
"text/template"
)
var (
templateFunctions = template.FuncMap{}
templateFunctionsLock sync.Mutex
)
func registerFunction(name string, f interface{}) error {
templateFunctionsLock.Lock()
defer templateFunctionsLock.Unlock()
if _, ok := templateFunctions[name]; ok {
return errors.New("Duplicate function for name " + name)
}
templateFunctions[name] = f
return nil
}
// GetFunctionMap exports all functions used in korvike to be used in own projects
// Example:
// import korvike "github.com/Luzifer/korvike"
// tpl := template.New("mytemplate").Funcs(korvike.GetFunctionMap())
func GetFunctionMap() template.FuncMap {
return templateFunctions
}