We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Question: 为什么在NewRequest()方法中给index成员变量赋值为-1,同时在Request对象的RouterSlicesNext()方法中第一行r.index++, 意为在-1的基础上加一。但是如果直接在初始化时给int类型的默认值,那么在RouterSlicesNext()方法中就可以直接执行for循环,而不用额外执行r.index++语句。请问这样设计是出于什么目的吗?
func NewRequest(conn ziface.IConnection, msg ziface.IMessage) ziface.IRequest { ... ... req.index = -1 return req }
func (r *Request) RouterSlicesNext() { r.index++ for r.index < int8(len(r.handlers)) { r.handlers[r.index](r) r.index++ } }
The text was updated successfully, but these errors were encountered:
执行 r.index++ 是为了执行切片中的下一个函数,路由开始执行就调用 RouterSlicesNext() 从0开始,但执行到中间的函数,例如第二个函数的调用 RouterSlicesNext() 是期望执行第三个函数,需要去 r.index++,也就导致了赋值需要为 -1
Sorry, something went wrong.
No branches or pull requests
Question: 为什么在NewRequest()方法中给index成员变量赋值为-1,同时在Request对象的RouterSlicesNext()方法中第一行r.index++, 意为在-1的基础上加一。但是如果直接在初始化时给int类型的默认值,那么在RouterSlicesNext()方法中就可以直接执行for循环,而不用额外执行r.index++语句。请问这样设计是出于什么目的吗?
The text was updated successfully, but these errors were encountered: