mirror of
https://github.com/Luzifer/korvike.git
synced 2024-11-12 17:22:44 +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>
21 lines
395 B
Go
21 lines
395 B
Go
package functions
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
func init() {
|
|
registerFunction("file", func(name string, v ...string) string {
|
|
defaultValue := ""
|
|
if len(v) > 0 {
|
|
defaultValue = v[0]
|
|
}
|
|
if _, err := os.Stat(name); err == nil {
|
|
//#nosec:G304 // Intended to load custom file
|
|
if rawValue, err := os.ReadFile(name); err == nil {
|
|
return string(rawValue)
|
|
}
|
|
}
|
|
return defaultValue
|
|
})
|
|
}
|