1
0
Fork 0
mirror of https://github.com/Luzifer/korvike.git synced 2024-11-14 02:02:41 +00:00
korvike/functions/func_file.go

22 lines
363 B
Go
Raw Normal View History

2016-09-14 11:06:04 +00:00
package functions
2016-08-24 10:31:37 +00:00
import (
"io/ioutil"
"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 {
if rawValue, err := ioutil.ReadFile(name); err == nil {
return string(rawValue)
}
}
return defaultValue
})
}