github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/router.go (about) 1 package kiwi 2 3 import "github.com/15mga/kiwi/util" 4 5 var ( 6 _Router IRouter 7 ) 8 9 func Router() IRouter { 10 return _Router 11 } 12 13 func SetRouter(router IRouter) { 14 _Router = router 15 } 16 17 type PktToKey func(pkt IRcvPkt) string 18 19 type WorkerFn func(id string, fn util.FnAnySlc, params ...any) 20 21 type IRouter interface { 22 AddRequest(req ISndRequest) 23 DelRequest(tid int64) 24 BindPus(svc TSvc, code TCode, fn FnRcvPus) 25 BindReq(svc TSvc, code TCode, fn FnRcvReq) 26 OnPush(pkt IRcvPush) 27 OnRequest(pkt IRcvRequest) 28 OnResponseOk(tid int64, head util.M, msg util.IMsg) 29 OnResponseOkBytes(tid int64, head util.M, bytes []byte) 30 OnResponseFail(tid int64, head util.M, code uint16) 31 WatchNotice(msg util.IMsg, handler NotifyHandler) 32 GetWatchCodes(svc TSvc) ([]TCode, bool) 33 OnNotice(pkt IRcvNotice) 34 }