{"record":{"id":"86e66d3c314cd24d","repo":"flipped-aurora/gin-vue-admin","slug":"error-86e66d","errorCode":null,"errorMessage":"已注册,无法重复注册","messagePattern":"已注册,无法重复注册","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/utils/validator.go","lineNumber":25,"sourceCode":"\t\"strconv\"\n\t\"strings\"\n)\n\ntype Rules map[string][]string\n\ntype RulesMap map[string]Rules\n\nvar CustomizeMap = make(map[string]Rules)\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: RegisterRule\n//@description: 注册自定义规则方案建议在路由初始化层即注册\n//@param: key string, rule Rules\n//@return: err error\n\nfunc RegisterRule(key string, rule Rules) (err error) {\n\tif CustomizeMap[key] != nil {\n\t\treturn errors.New(key + \"已注册,无法重复注册\")\n\t} else {\n\t\tCustomizeMap[key] = rule\n\t\treturn nil\n\t}\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: NotEmpty\n//@description: 非空 不能为其对应类型的0值\n//@return: string\n\nfunc NotEmpty() string {\n\treturn \"notEmpty\"\n}\n\n// @author: [zooqkl](https://github.com/zooqkl)\n// @function: RegexpMatch\n// @description: 正则校验 校验输入项是否满足正则表达式","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/validator.go#L7-L43","documentation":"Returned by validator.RegisterRule() when a custom validation rule key already exists in CustomizeMap. The map is global, so registering the same key twice (across router init or plugin init) is rejected to prevent silent rule overwrites.","triggerScenarios":"Calling utils.RegisterRule(key, rule) more than once for the same key — typically re-running router initialization, registering the same rule in both main and a plugin, or hot-reload paths re-invoking init.","commonSituations":"Duplicate registration in initialize/router.go and a plugin's own init, calling RegisterRule in a function invoked per-request instead of once at startup, or two modules choosing the same rule key.","solutions":["Register each rule key only once, at router initialization time","Guard with a check: skip registration if utils.CustomizeMap[key] already exists","Rename one of the colliding keys to a unique namespace","If intentional override is needed, extend the validator with an explicit overwrite API instead of re-registering"],"exampleFix":"// before\nfunc init() {\n    utils.RegisterRule(\"PwdVerify\", utils.PwdVerify) // may run twice\n}\n// after\nif utils.CustomizeMap[\"PwdVerify\"] == nil {\n    utils.RegisterRule(\"PwdVerify\", utils.PwdVerify)\n}","handlingStrategy":"validation","validationCode":"if utils.CustomizeMap[\"MyRule\"] != nil {\n    // already registered, skip\n} else {\n    utils.RegisterRule(\"MyRule\", myRule)\n}","typeGuard":null,"tryCatchPattern":"if err := utils.RegisterRule(\"MyRule\", myRule); err != nil {\n    // duplicate registration: log at debug and continue, or treat as fatal per your policy\n    log.Printf(\"rule already registered: %v\", err)\n}","preventionTips":["Register custom rules only once during router initialization","Use unique, namespaced rule keys per module/plugin","Never call RegisterRule inside per-request handlers","Check CustomizeMap before registering when init paths may run twice"],"tags":["validation","validator","duplicate-registration","go"],"backgroundTag":"duplicate-rule-registration","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}