mirror of
https://github.com/Luzifer/korvike.git
synced 2024-12-29 23:51:16 +00:00
Knut Ahlers
fd2a37ca97
and add `must*` variants for them Signed-off-by: Knut Ahlers <knut@ahlers.me>
27 lines
472 B
Go
27 lines
472 B
Go
package functions
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func init() {
|
|
registerFunction("file", func(name string) string {
|
|
fc, err := tplReadFile(name)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return fc
|
|
})
|
|
|
|
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
|
|
}
|