From e725192072e9fa9bd40a71852c37747b8e06ca3b Mon Sep 17 00:00:00 2001 From: qiantao Date: Thu, 25 Jun 2020 22:11:32 +0800 Subject: [PATCH] fix #4000 --- validation/validators.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/validation/validators.go b/validation/validators.go index ac00a72c..46b5e764 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -16,9 +16,11 @@ package validation import ( "fmt" + "github.com/astaxie/beego/logs" "reflect" "regexp" "strings" + "sync" "time" "unicode/utf8" ) @@ -57,6 +59,8 @@ var MessageTmpls = map[string]string{ "ZipCode": "Must be valid zipcode", } +var once sync.Once + // SetDefaultMessage set default messages // if not set, the default messages are // "Required": "Can not be empty", @@ -84,9 +88,12 @@ func SetDefaultMessage(msg map[string]string) { return } - for name := range msg { - MessageTmpls[name] = msg[name] - } + once.Do(func() { + for name := range msg { + MessageTmpls[name] = msg[name] + } + }) + logs.Warn(`you must SetDefaultMessage at once`) } // Validator interface