entc: adding fail method to template engine

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-07-12 13:52:30 +03:00
parent 71feecbc07
commit f7d4a52e68

View File

@@ -6,6 +6,7 @@ package gen
import (
"bytes"
"errors"
"fmt"
"path/filepath"
"reflect"
@@ -63,6 +64,7 @@ var (
"unset": unset,
"hasKey": hasKey,
"list": list,
"fail": fail,
}
rules = ruleset()
acronyms = make(map[string]struct{})
@@ -431,3 +433,8 @@ func hasKey(d map[string]interface{}, key string) bool {
func list(v ...interface{}) []interface{} {
return v
}
// fail unconditionally returns an empty string and an error with the specified text.
func fail(msg string) (string, error) {
return "", errors.New(msg)
}