fix(hz): use regexp to check if there are duplicate register func in router #1029
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
fix
Check the PR title.
(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
andnamespace b
, hz will import two packages in theregister.go
of the router, which area_b
andb
.At this time, hz also needs to add
a_b.register(r)
andb.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.b
和namespace b
时,hz 会在 router 的register.go
中引入两个包,分别是a_b
和b
。此时 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: