flipped-aurora/gin-vue-admin · warning

已注册,无法重复注册

Error message

已注册,无法重复注册

What it means

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.

Source

Thrown at server/utils/validator.go:25

	"strconv"
	"strings"
)

type Rules map[string][]string

type RulesMap map[string]Rules

var CustomizeMap = make(map[string]Rules)

//@author: [piexlmax](https://github.com/piexlmax)
//@function: RegisterRule
//@description: 注册自定义规则方案建议在路由初始化层即注册
//@param: key string, rule Rules
//@return: err error

func RegisterRule(key string, rule Rules) (err error) {
	if CustomizeMap[key] != nil {
		return errors.New(key + "已注册,无法重复注册")
	} else {
		CustomizeMap[key] = rule
		return nil
	}
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: NotEmpty
//@description: 非空 不能为其对应类型的0值
//@return: string

func NotEmpty() string {
	return "notEmpty"
}

// @author: [zooqkl](https://github.com/zooqkl)
// @function: RegexpMatch
// @description: 正则校验 校验输入项是否满足正则表达式

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Register each rule key only once, at router initialization time
  2. Guard with a check: skip registration if utils.CustomizeMap[key] already exists
  3. Rename one of the colliding keys to a unique namespace
  4. If intentional override is needed, extend the validator with an explicit overwrite API instead of re-registering

Example fix

// before
func init() {
    utils.RegisterRule("PwdVerify", utils.PwdVerify) // may run twice
}
// after
if utils.CustomizeMap["PwdVerify"] == nil {
    utils.RegisterRule("PwdVerify", utils.PwdVerify)
}
Defensive patterns

Strategy: validation

Validate before calling

if utils.CustomizeMap["MyRule"] != nil {
    // already registered, skip
} else {
    utils.RegisterRule("MyRule", myRule)
}

Try / catch

if err := utils.RegisterRule("MyRule", myRule); err != nil {
    // duplicate registration: log at debug and continue, or treat as fatal per your policy
    log.Printf("rule already registered: %v", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/86e66d3c314cd24d. Report an issue: GitHub.