github.com/zhongdalu/gf@v1.0.0/g/util/gvalid/gvalid_message.go (about)

     1  // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // 默认的错误消息定义。
     8  
     9  package gvalid
    10  
    11  // 默认规则校验错误消息(可以通过接口自定义错误消息)
    12  var defaultMessages = map[string]string{
    13  	"required":             "字段不能为空",
    14  	"required-if":          "字段不能为空",
    15  	"required-unless":      "字段不能为空",
    16  	"required-with":        "字段不能为空",
    17  	"required-with-all":    "字段不能为空",
    18  	"required-without":     "字段不能为空",
    19  	"required-without-all": "字段不能为空",
    20  	"date":                 "日期格式不正确",
    21  	"date-format":          "日期格式不正确",
    22  	"email":                "邮箱地址格式不正确",
    23  	"phone":                "手机号码格式不正确",
    24  	"telephone":            "电话号码格式不正确",
    25  	"passport":             "账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间",
    26  	"password":             "密码格式不合法,密码格式为任意6-18位的可见字符",
    27  	"password2":            "密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字",
    28  	"password3":            "密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符",
    29  	"postcode":             "邮政编码不正确",
    30  	"id-number":            "身份证号码不正确",
    31  	"qq":                   "QQ号码格式不正确",
    32  	"ip":                   "IP地址格式不正确",
    33  	"ipv4":                 "IPv4地址格式不正确",
    34  	"ipv6":                 "IPv6地址格式不正确",
    35  	"mac":                  "MAC地址格式不正确",
    36  	"url":                  "URL地址格式不正确",
    37  	"domain":               "域名格式不正确",
    38  	"length":               "字段长度为:min到:max个字符",
    39  	"min-length":           "字段最小长度为:min",
    40  	"max-length":           "字段最大长度为:max",
    41  	"between":              "字段大小为:min到:max",
    42  	"min":                  "字段最小值为:min",
    43  	"max":                  "字段最大值为:max",
    44  	"json":                 "字段应当为JSON格式",
    45  	"xml":                  "字段应当为XML格式",
    46  	"array":                "字段应当为数组",
    47  	"integer":              "字段应当为整数",
    48  	"float":                "字段应当为浮点数",
    49  	"boolean":              "字段应当为布尔值",
    50  	"same":                 "字段值不合法",
    51  	"different":            "字段值不合法",
    52  	"in":                   "字段值不合法",
    53  	"not-in":               "字段值不合法",
    54  	"regex":                "字段值不合法",
    55  }
    56  
    57  // 初始化错误消息管理对象
    58  func init() {
    59  	errorMsgMap.Sets(defaultMessages)
    60  }
    61  
    62  // 替换默认的错误提示为指定的自定义提示
    63  // 主要作用:
    64  // 1、便于多语言错误提示设置;
    65  // 2、默认错误提示信息不满意;
    66  func SetDefaultErrorMsgs(msgs map[string]string) {
    67  	errorMsgMap.Sets(msgs)
    68  }