hertz icon indicating copy to clipboard operation
hertz copied to clipboard

[hz] router register occur "the router(%s) has been registered"

Open apple-1024 opened this issue 10 months ago • 2 comments

Describe the bug

生成http接口代码时,增加路由注册,会判断是否重复存在,此处判断逻辑有点问题,会出现误判断导致代码生成失败,如:"strategy.Register(r)"和"appstrategy.Register(r)"出现冲突

To Reproduce

Steps to reproduce the behavior:

代码位置

https://github.com/cloudwego/hertz/tree/develop/cmd/hz/generator/router.go

if !bytes.Contains(file, []byte(register.DepPkg)) {
		file, err = util.AddImport(registerPath, register.DepPkgAlias, register.DepPkg)
		if err != nil {
			return err
		}

		insertReg := register.DepPkgAlias + ".Register(r)\n"
		if bytes.Contains(file, []byte(insertReg)) {
			return fmt.Errorf("the router(%s) has been registered", insertReg)
		}
...

Expected behavior strategy.Register(r)"和"appstrategy.Register(r) 可正常共存

Screenshots

Hertz version: v0.9.5

Environment:

Additional context

apple-1024 avatar Feb 14 '25 07:02 apple-1024

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

github-actions[bot] avatar Feb 14 '25 08:02 github-actions[bot]

ok, I will fix it later when I have time.

HeyJavaBean avatar Feb 26 '25 07:02 HeyJavaBean

Closed by #1403

xiaost avatar Aug 14 '25 10:08 xiaost