server/server_handlers.go

64 lines
1.3 KiB
Go
Raw Normal View History

2017-10-26 11:14:00 +00:00
package server
import (
"errors"
2017-11-15 04:13:47 +00:00
"fmt"
2017-11-01 06:58:26 +00:00
"log"
2017-10-26 11:14:00 +00:00
"net"
2017-11-15 04:13:47 +00:00
"git.loafle.net/commons_go/logging"
2017-10-26 11:14:00 +00:00
)
2017-11-15 04:16:31 +00:00
func NewServerHandler() ServerHandler {
sh := &ServerHandlers{}
return sh
}
2017-10-26 11:14:00 +00:00
type ServerHandlers struct {
2017-11-15 04:13:47 +00:00
// Server name for sending in response headers.
//
// Default server name is used if left blank.
Name string
2017-10-26 11:14:00 +00:00
}
2017-11-15 04:13:47 +00:00
func (sh *ServerHandlers) Init() error {
2017-10-27 08:53:26 +00:00
2017-11-15 04:13:47 +00:00
return nil
2017-10-27 08:53:26 +00:00
}
2017-10-26 11:14:00 +00:00
func (sh *ServerHandlers) Listen() (net.Listener, error) {
return nil, errors.New("Server: Handler method[Listen] of Server is not implement")
}
2017-11-15 04:13:47 +00:00
// 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) {
2017-11-01 05:22:52 +00:00
return conn, nil
2017-10-27 07:14:20 +00:00
}
2017-11-01 05:22:52 +00:00
func (sh *ServerHandlers) Handle(conn net.Conn, stopChan <-chan struct{}, doneChan chan<- struct{}) {
2017-11-01 06:58:26 +00:00
log.Printf("Server.Handle")
2017-10-26 11:14:00 +00:00
}
2017-11-15 04:13:47 +00:00
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
}
2017-10-26 11:14:00 +00:00
func (sh *ServerHandlers) Validate() {
}