Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hz): use regexp to check if there are duplicate register func in router #1029

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ozline
Copy link

@ozline ozline commented Dec 15, 2023

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

使用正则表达式来判断 router/register.go 中是否存在同名的注册函数(xxx.register(r))

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

When there are two namespaces with the same ending, such as namespace go a.b and namespace b, hz will import two packages in the register.go of the router, which are a_b and b.

At this time, hz also needs to add a_b.register(r) and b.register(r) in the register function.

Due to the current version's judgment based on text matching, when a_b.register(r) has been added, b.register(r) will be judged as an existing function with the same name and throw an error.

The purpose of this PR is to use regxp instead of current text matching to find whether there are duplicate registration functions in register.go, in order to solve this problem.

zh(optional):

当出现两个同结尾的命名空间,例如namespace go a.bnamespace b时,hz 会在 router 的 register.go中引入两个包,分别是 a_bb

此时 hz 还需要在register 函数中加入a_b.register(r)b.register(r)

由于当前版本判定是根据文本匹配,导致当已加入a_b.register(r)时,b.register(r)会被判定为已经存在同名函数而抛出错误。

这个 pr 的目的是使用正则表达式替代当前的文本匹配在 register.go 中查找是否存在同名的注册函数,以解决这个问题。

(Optional) Which issue(s) this PR fixes:

#1028

(Optional) The PR that updates user documentation:

@welkeyever
Copy link
Member

Maybe add some UTs for this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants