RegisterHandlers 시그니쳐 변경

This commit is contained in:
2024-07-29 10:15:04 +09:00
parent 013c89e58d
commit ae98abe61d
3 changed files with 13 additions and 5 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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 {