1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 06:00:55 +00:00

Merge pull request #4017 from guhan121/fix#4000

Prohibit multiple calls SetDefaultMessage.
This commit is contained in:
Ming Deng 2020-06-26 17:49:36 +08:00 committed by GitHub
commit 8039cc8e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,9 +16,11 @@ package validation
import ( import (
"fmt" "fmt"
"github.com/astaxie/beego/logs"
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
"sync"
"time" "time"
"unicode/utf8" "unicode/utf8"
) )
@ -57,6 +59,8 @@ var MessageTmpls = map[string]string{
"ZipCode": "Must be valid zipcode", "ZipCode": "Must be valid zipcode",
} }
var once sync.Once
// SetDefaultMessage set default messages // SetDefaultMessage set default messages
// if not set, the default messages are // if not set, the default messages are
// "Required": "Can not be empty", // "Required": "Can not be empty",
@ -84,9 +88,12 @@ func SetDefaultMessage(msg map[string]string) {
return return
} }
once.Do(func() {
for name := range msg { for name := range msg {
MessageTmpls[name] = msg[name] MessageTmpls[name] = msg[name]
} }
})
logs.Warn(`you must SetDefaultMessage at once`)
} }
// Validator interface // Validator interface