{"record":{"id":"7f2c561f8c4eef00","repo":"flipped-aurora/gin-vue-admin","slug":"error-7f2c56","errorCode":null,"errorMessage":"长度或值不在合法范围,","messagePattern":"长度或值不在合法范围,","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/utils/validator.go","lineNumber":163,"sourceCode":"\t\tif tagVal.Anonymous && tagVal.Type.Kind() == reflect.Struct {\n\t\t\tif err = Verify(val.Interface(), roleMap); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\tif len(roleMap[tagVal.Name]) > 0 {\n\t\t\tfor _, v := range roleMap[tagVal.Name] {\n\t\t\t\tswitch {\n\t\t\t\tcase v == \"notEmpty\":\n\t\t\t\t\tif isBlank(val) {\n\t\t\t\t\t\treturn errors.New(tagVal.Name + \"值不能为空\")\n\t\t\t\t\t}\n\t\t\t\tcase strings.Split(v, \"=\")[0] == \"regexp\":\n\t\t\t\t\tif !regexpMatch(strings.Split(v, \"=\")[1], val.String()) {\n\t\t\t\t\t\treturn errors.New(tagVal.Name + \"格式校验不通过\")\n\t\t\t\t\t}\n\t\t\t\tcase compareMap[strings.Split(v, \"=\")[0]]:\n\t\t\t\t\tif !compareVerify(val, v) {\n\t\t\t\t\t\treturn errors.New(tagVal.Name + \"长度或值不在合法范围,\" + v)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: compareVerify\n//@description: 长度和数字的校验方法 根据类型自动校验\n//@param: value reflect.Value, VerifyStr string\n//@return: bool\n\nfunc compareVerify(value reflect.Value, VerifyStr string) bool {\n\tswitch value.Kind() {\n\tcase reflect.String:\n\t\treturn compare(len([]rune(value.String())), VerifyStr)","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/validator.go#L145-L181","documentation":"Verify's compare rules come from compareMap and are dispatched to compareVerify(val, v). When a rule such as max=10, min=1, or eq=xxx fails, Verify returns errors.New(fieldName + \"长度或值不在合法范围,\" + v) — '<Field> length or value not in legal range, <rule>'. The raw rule text is appended so the caller can see which comparison failed.","triggerScenarios":"A field tagged e.g. mj:\"max=5\" receives a string longer than 5 characters or a numeric value above the bound; mj:\"min=1\" receives 0 or an empty slice-dependent value; any compareMap key (max/min/eq) whose compareVerify check returns false.","commonSituations":"Users submit over-long inputs (comments, names) that the DB column would reject; pagination/page-size fields below minimum; version drift where the tag's bound no longer matches business limits; callers forgetting the rule compares string length for string kinds and numeric value for numeric kinds.","solutions":["Read the appended rule text (e.g. \",max=10\") to see the exact bound violated, then adjust the submitted value to satisfy it.","Enforce the same limits on the frontend (maxlength, min/max attributes) so users never hit the server error.","Update the `mj:` tag bounds if business requirements legitimately changed.","If you need a different semantic (bytes vs runes, numeric vs length), adjust compareVerify or the field type rather than weakening the rule."],"exampleFix":"// before\nNickName string `json:\"nickName\" mj:\"max=5\"` // value \"this-is-way-too-long\"\n\n// after\nNickName string `json:\"nickName\" mj:\"max=30\"` // frontend maxlength=\"30\" and value trimmed to fit","handlingStrategy":"validation","validationCode":"if utf8.RuneCountInString(req.NickName) > 30 {\n    return errors.New(\"nickName exceeds 30 characters\")\n}","typeGuard":null,"tryCatchPattern":"if err := utils.Verify(req, utils.Rules{}); err != nil {\n    if strings.Contains(err.Error(), \"长度或值不在合法范围\") {\n        c.JSON(400, gin.H{\"msg\": err.Error()})\n        return\n    }\n    return err\n}","preventionTips":["Enforce the same min/max limits on the frontend inputs","Keep `mj:max/min` bounds in sync with DB column sizes","Remember string rules check length, numeric kinds check value","Clamp page-size style inputs to allowed ranges before validating"],"tags":["go","validation","gin-vue-admin"],"backgroundTag":"value-out-of-range","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}