server-go/socket/net/server-handler.go

65 lines
1.2 KiB
Go
Raw Normal View History

2018-04-04 04:01:26 +00:00
package net
import (
"net"
"git.loafle.net/commons/server-go"
2018-04-05 15:15:29 +00:00
"git.loafle.net/commons/server-go/socket"
2018-04-04 04:01:26 +00:00
)
type ServerHandler interface {
2018-04-05 15:15:29 +00:00
socket.ServerHandler
2018-04-04 04:01:26 +00:00
OnError(serverCtx server.ServerCtx, conn net.Conn, status int, reason error)
RegisterServlet(servlet Servlet)
2018-04-04 16:51:34 +00:00
Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet
2018-04-04 04:01:26 +00:00
}
type ServerHandlers struct {
server.ServerHandlers
servlet Servlet
}
func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error {
if err := sh.ServerHandlers.Init(serverCtx); nil != err {
return err
}
if nil != sh.servlet {
if err := sh.servlet.Init(serverCtx); nil != err {
return err
}
}
return nil
}
func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) {
if nil != sh.servlet {
sh.servlet.Destroy(serverCtx)
}
sh.ServerHandlers.Destroy(serverCtx)
}
func (sh *ServerHandlers) OnError(serverCtx server.ServerCtx, conn net.Conn, status int, reason error) {
}
func (sh *ServerHandlers) RegisterServlet(servlet Servlet) {
sh.servlet = servlet
}
2018-04-04 16:51:34 +00:00
func (sh *ServerHandlers) Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet {
2018-04-04 04:01:26 +00:00
return sh.servlet
}
func (sh *ServerHandlers) Validate() error {
if err := sh.ServerHandlers.Validate(); nil != err {
return err
}
return nil
}