未验证 提交 8039cc8e 编写于 作者: M Ming Deng 提交者: GitHub

Merge pull request #4017 from guhan121/fix#4000

Prohibit multiple calls SetDefaultMessage.
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册