1
0
mirror of https://github.com/Luzifer/korvike.git synced 2024-09-19 17:02:57 +00:00
korvike/functions/collect.go

31 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
}