diff --git a/server.go b/server.go index e4336a3..c6067f3 100644 --- a/server.go +++ b/server.go @@ -40,6 +40,13 @@ func init() { gob.Register([]any{}) } +type ServerMuxInterface interface { + http.Handler + + HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) + Handle(pattern string, handler http.Handler) +} + const ( // HTTPStatusReloginRequired : http status를 이걸 받으면 클라이언트는 로그아웃하고 로그인 화면으로 돌아가야 한다. HTTPStatusReloginRequired = 599 @@ -140,7 +147,7 @@ func isTlsEnabled(fileout ...*string) bool { } // NewHTTPServer : -func NewHTTPServerWithPort(serveMux *http.ServeMux, port int) *Server { +func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server { if isTlsEnabled() && port == 80 { port = 443 } @@ -157,7 +164,7 @@ func NewHTTPServerWithPort(serveMux *http.ServeMux, port int) *Server { return server } -func NewHTTPServer(serveMux *http.ServeMux) *Server { +func NewHTTPServer(serveMux ServerMuxInterface) *Server { // 시작시 자동으로 enable됨 if isTlsEnabled() && *portptr == 80 { diff --git a/wshandler/wshandler.go b/wshandler/wshandler.go index b4c3e95..2e56fe1 100644 --- a/wshandler/wshandler.go +++ b/wshandler/wshandler.go @@ -266,7 +266,7 @@ func (ws *WebsocketHandler) Cleanup() { ws.connWaitGroup.Wait() } -func (ws *WebsocketHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error { +func (ws *WebsocketHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface, prefix string) error { url := gocommon.MakeHttpHandlerPattern(prefix, "ws") if *noAuthFlag { serveMux.HandleFunc(url, ws.upgrade_nosession) diff --git a/wshandler/wshandler_peer.go b/wshandler/wshandler_peer.go index 937c3ba..96e3ebc 100644 --- a/wshandler/wshandler_peer.go +++ b/wshandler/wshandler_peer.go @@ -11,6 +11,7 @@ import ( "time" "go.mongodb.org/mongo-driver/bson/primitive" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/session" @@ -18,7 +19,7 @@ import ( ) type WebsocketPeerHandler interface { - RegisterHandlers(serveMux *http.ServeMux, prefix string) error + RegisterHandlers(serveMux gocommon.ServerMuxInterface, prefix string) error } type peerCtorChannelValue struct { @@ -164,7 +165,7 @@ func NewWebsocketPeerHandler[T PeerInterface](consumer session.Consumer, creator return wsh } -func (ws *websocketPeerHandler[T]) RegisterHandlers(serveMux *http.ServeMux, prefix string) error { +func (ws *websocketPeerHandler[T]) RegisterHandlers(serveMux gocommon.ServerMuxInterface, prefix string) error { if *noAuthFlag { serveMux.HandleFunc(prefix, ws.upgrade_noauth) } else {