Skip to content

Commit

Permalink
fix: hz uses regular expressions to check if there are duplicate regi…
Browse files Browse the repository at this point in the history
…stration functions in router/register.go
  • Loading branch information
ozline authored Dec 15, 2023
1 parent 82f9bfa commit a007edb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/hz/generator/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ func (pkgGen *HttpPackageGenerator) updateRegister(pkg, rDir, pkgName string) er
}

insertReg := register.DepPkgAlias + ".Register(r)\n"
if bytes.Contains(file, []byte(insertReg)) {

registerPattern := `(?m)^\s*` + register.DepPkgAlias + `\s*\.\s*Register\(r\)\s*$`
re := regexp.MustCompile(registerPattern)
if re.Match(file) {
return fmt.Errorf("the router(%s) has been registered", insertReg)
}

Expand Down

0 comments on commit a007edb

Please sign in to comment.