package server import ( "errors" "fmt" "net" "git.loafle.net/commons_go/logging" ) func NewServerHandler() ServerHandler { sh := &ServerHandlers{} return sh } type ServerHandlers struct { // Server name for sending in response headers. // // Default server name is used if left blank. Name string } func (sh *ServerHandlers) Init() error { return nil } func (sh *ServerHandlers) Listen() (net.Listener, error) { return nil, errors.New("Server: Handler method[Listen] of Server is not implement") } // OnStart invoked when server is stated // If you override ths method, must call func (sh *ServerHandlers) OnStart() { // no op } func (sh *ServerHandlers) OnConnect(conn net.Conn) (net.Conn, error) { return conn, nil } func (sh *ServerHandlers) Handle(conn net.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) { } func (sh *ServerHandlers) OnError(status int, reason error) { logging.Logger().Error(fmt.Sprintf("Server: error status: %d, reason: %v", status, reason)) } // OnStop invoked when server is stopped // If you override ths method, must call func (sh *ServerHandlers) OnStop() { // no op } func (sh *ServerHandlers) GetName() string { return sh.Name } func (sh *ServerHandlers) Validate() { }