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

31 lines
716 B
Go
Raw Normal View History

2016-09-14 11:06:04 +00:00
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
}