mirror of
https://github.com/Luzifer/korvike.git
synced 2024-12-29 23:51:16 +00:00
Knut Ahlers
e8a8b2f83f
Breaking changes: - Remove function `b64decode`, use `b64dec` - Remove function `b64encode`, use `b64enc` - Remove default from `env`, use `env "MYVAR" | default "..."` - Remove function `hash`, use `sha1sum` / `sha256sum` / `sha512sum` - Function `now` returns `time.Time`, use `now | date "[format]"` - Function `split` now has reversed parameters `split <sep> <str>` Signed-off-by: Knut Ahlers <knut@ahlers.me>
36 lines
861 B
Go
36 lines
861 B
Go
// Package functions contains custom functions specific to korvike and
|
|
// returns the sprig functions with added korvike specific functions
|
|
package functions
|
|
|
|
import (
|
|
"log"
|
|
"sync"
|
|
"text/template"
|
|
|
|
"github.com/Masterminds/sprig/v3"
|
|
)
|
|
|
|
var (
|
|
templateFunctions = sprig.FuncMap()
|
|
templateFunctionsLock sync.Mutex
|
|
)
|
|
|
|
func registerFunction(name string, f interface{}) {
|
|
templateFunctionsLock.Lock()
|
|
defer templateFunctionsLock.Unlock()
|
|
|
|
if _, ok := templateFunctions[name]; ok {
|
|
log.Printf("overwriting existing function %q", name)
|
|
}
|
|
|
|
templateFunctions[name] = f
|
|
}
|
|
|
|
// 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
|
|
}
|