package plain import ( "git.noahlan.cn/noahlan/nnet/conn" "git.noahlan.cn/noahlan/nnet/packet" "git.noahlan.cn/noahlan/nnet/router" "git.noahlan.cn/noahlan/ntool/nlog" ) type Router struct { plainHandler router.Handler notFound router.Handler } func NewRouter() router.Router { return &Router{} } func (r *Router) Handle(nc *conn.Connection, pkg packet.IPacket) { if r.plainHandler == nil { if r.notFound == nil { nlog.Error("message handler not found") return } r.notFound.Handle(nc, pkg) return } r.plainHandler.Handle(nc, pkg) } func (r *Router) Register(_ any, handler router.Handler) error { r.plainHandler = handler return nil } func (r *Router) SetNotFoundHandler(handler router.Handler) { r.notFound = handler }