2016-09-14 11:06:04 +00:00
|
|
|
package functions
|
2016-08-24 10:31:37 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-29 16:55:20 +00:00
|
|
|
"fmt"
|
2016-08-24 10:31:37 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-02-29 16:55:20 +00:00
|
|
|
registerFunction("file", func(name string) string {
|
|
|
|
fc, err := tplReadFile(name)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
2016-08-24 10:31:37 +00:00
|
|
|
}
|
2024-02-29 16:55:20 +00:00
|
|
|
return fc
|
2016-08-24 10:31:37 +00:00
|
|
|
})
|
2024-02-29 16:55:20 +00:00
|
|
|
|
|
|
|
registerFunction("mustFile", tplReadFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tplReadFile(name string) (string, error) {
|
|
|
|
rawValue, err := os.ReadFile(name) //#nosec:G304 // Intended to load custom file
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("reading file: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(rawValue), nil
|
2016-08-24 10:31:37 +00:00
|
|
|
}
|