server-go/net/server-handler.go
crusader f85b949e66 ing
2018-04-04 13:01:26 +09:00

68 lines
1.2 KiB
Go

package net
import (
"net"
"git.loafle.net/commons/server-go"
)
type ServerHandler interface {
server.ServerHandler
OnError(serverCtx server.ServerCtx, conn net.Conn, status int, reason error)
RegisterServlet(servlet Servlet)
Servlet() Servlet
}
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
}
func (sh *ServerHandlers) Servlet() Servlet {
return sh.servlet
}
func (sh *ServerHandlers) Validate() error {
if err := sh.ServerHandlers.Validate(); nil != err {
return err
}
if 0 >= sh.Concurrency {
sh.Concurrency = 0
}
return nil
}