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
func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...ziface.RouterHandler) { // 1. Check if the API handler method bound to the current msg already exists if _, ok := r.Apis[msgId]; ok { panic("repeated api , msgId = " + strconv.Itoa(int(msgId))) } finalSize := len(r.Handlers) + len(Handlers) mergedHandlers := make([]ziface.RouterHandler, finalSize) copy(mergedHandlers, r.Handlers) copy(mergedHandlers[len(r.Handlers):], Handlers) r.Apis[msgId] = append(r.Apis[msgId], mergedHandlers...) }
type RouterSlices struct { Apis map[uint32][]ziface.RouterHandler Handlers []ziface.RouterHandler sync.RWMutex }
我不理解这个结构体中Handlers的意义,我的理解应该是每一个msgid有一个自己的handler切片,但是可以添加handler,为什么要判断当前msgid是否在map中存在,此外为什么新的msgID需要加上原来的r.Handlers,还有是不是需要加一个写锁,防止并发安全的问题,望解答!!!
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
不需要锁,路由设置应该是服务器初始化的时候完成的,服务器启动后不应该再去修改路由
No branches or pull requests
我不理解这个结构体中Handlers的意义,我的理解应该是每一个msgid有一个自己的handler切片,但是可以添加handler,为什么要判断当前msgid是否在map中存在,此外为什么新的msgID需要加上原来的r.Handlers,还有是不是需要加一个写锁,防止并发安全的问题,望解答!!!
The text was updated successfully, but these errors were encountered: