From f7d4a52e681cb97fefec64df9e56234cb3ba094f Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Sun, 12 Jul 2020 13:52:30 +0300 Subject: [PATCH] entc: adding fail method to template engine Signed-off-by: Alex Snast --- entc/gen/func.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/entc/gen/func.go b/entc/gen/func.go index c07c82918..6ad3926bb 100644 --- a/entc/gen/func.go +++ b/entc/gen/func.go @@ -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) +}