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

中间件源码有个疑问 #44

Open
sportwxp opened this issue Oct 6, 2021 · 1 comment
Open

中间件源码有个疑问 #44

sportwxp opened this issue Oct 6, 2021 · 1 comment

Comments

@sportwxp
Copy link

sportwxp commented Oct 6, 2021

func (c *Context) Next() {
c.index++
s := len(c.handlers)
for ; c.index < s; c.index++ {
c.handlers[c.index](c)
}
}

这里的for循环是不是应该改为直接调用下一个Handler

func (c *Context) Next() {
c.index++
s := len(c.handlers)
if c.index < s {
c.handlers[c.index](c)
}
}

@ln2037
Copy link

ln2037 commented Nov 21, 2021

博客里提到了,不是所有的中间件都会调用这个next函数。若不采用for循环的做法,使用的中间件没有调用next的话,那么无法执行下一个HandlerFunc。

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

No branches or pull requests

2 participants