Esempio n. 1
0
// getEventHandlerChain 获取 HandlerChain 以处理事件类型为 EventType 的事件, 如果没有找到返回 nil.
func (mux *ServeMux) getEventHandlerChain(eventType EventType) (handlers HandlerChain) {
	if m := mux.eventHandlerChainMap; len(m) > 0 {
		handlers = m[EventType(util.ToLower(string(eventType)))]
		if len(handlers) == 0 {
			handlers = mux.defaultEventHandlerChain
		}
	} else {
		handlers = mux.defaultEventHandlerChain
	}
	return
}
Esempio n. 2
0
// getMsgHandlerChain 获取 HandlerChain 以处理消息类型为 MsgType 的消息, 如果没有找到返回 nil.
func (mux *ServeMux) getMsgHandlerChain(msgType MsgType) (handlers HandlerChain) {
	if m := mux.msgHandlerChainMap; len(m) > 0 {
		handlers = m[MsgType(util.ToLower(string(msgType)))]
		if len(handlers) == 0 {
			handlers = mux.defaultMsgHandlerChain
		}
	} else {
		handlers = mux.defaultMsgHandlerChain
	}
	return
}
Esempio n. 3
0
// EventHandle 设置 handlers 以处理特定类型的事件.
func (mux *ServeMux) EventHandle(eventType EventType, handlers ...Handler) {
	mux.startedChecker.check()
	if len(handlers) == 0 {
		return
	}
	for _, h := range handlers {
		if h == nil {
			panic("handler can not be nil")
		}
	}
	mux.eventHandlerChainMap[EventType(util.ToLower(string(eventType)))] = combineHandlerChain(mux.eventMiddlewares, handlers)
}
Esempio n. 4
0
// EventHandleFunc 设置 handlers 以处理特定类型的事件.
func (mux *ServeMux) EventHandleFunc(eventType EventType, handlers ...func(*Context)) {
	mux.startedChecker.check()
	if len(handlers) == 0 {
		return
	}
	for _, h := range handlers {
		if h == nil {
			panic("handler can not be nil")
		}
	}
	handlers2 := make(HandlerChain, len(handlers))
	for i := 0; i < len(handlers); i++ {
		handlers2[i] = HandlerFunc(handlers[i])
	}
	mux.eventHandlerChainMap[EventType(util.ToLower(string(eventType)))] = combineHandlerChain(mux.eventMiddlewares, handlers2)
}