ing
This commit is contained in:
parent
42c49a5914
commit
9d3486ca28
11
server.go
11
server.go
|
@ -72,13 +72,11 @@ func (s *server) Start() error {
|
||||||
|
|
||||||
s.listener = newGracefulListener(listener, s.sh.GetMaxStopWaitTime())
|
s.listener = newGracefulListener(listener, s.sh.GetMaxStopWaitTime())
|
||||||
|
|
||||||
s.stopChan = make(chan struct{})
|
if err = s.sh.Init(); nil != err {
|
||||||
|
logging.Logger().Panic(fmt.Sprintf("Server: Initialization of server has been failed %v", err))
|
||||||
if err = s.sh.OnStart(); nil != err {
|
|
||||||
logging.Logger().Panic(fmt.Sprintf("Server: server cannot start %v", err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.Logger().Info(fmt.Sprintf("Server[%s] is started", s.sh.GetName()))
|
s.stopChan = make(chan struct{})
|
||||||
|
|
||||||
s.stopWg.Add(1)
|
s.stopWg.Add(1)
|
||||||
go handleServer(s)
|
go handleServer(s)
|
||||||
|
@ -109,6 +107,9 @@ func handleServer(s *server) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
logging.Logger().Info(fmt.Sprintf("Server[%s] is started", s.sh.GetName()))
|
||||||
|
s.sh.OnStart()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-s.stopChan:
|
case <-s.stopChan:
|
||||||
s.listener.Close()
|
s.listener.Close()
|
||||||
|
|
|
@ -8,11 +8,37 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerHandler interface {
|
type ServerHandler interface {
|
||||||
|
// Init invoked before the server is started
|
||||||
|
// If you override ths method, must call
|
||||||
|
//
|
||||||
|
// func (sh *ServerHandler) Init() error {
|
||||||
|
// if err := sh.ServerHandler.Init(); nil != err {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// ...
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
Init() error
|
||||||
Listen() (net.Listener, error)
|
Listen() (net.Listener, error)
|
||||||
|
// OnStart invoked when server is started
|
||||||
|
// If you override ths method, must call
|
||||||
|
//
|
||||||
|
// func (sh *ServerHandler) OnStart() error {
|
||||||
|
// sh.ServerHandler.OnStart()
|
||||||
|
// ...
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
OnStart()
|
||||||
|
|
||||||
CheckOrigin(ctx *fasthttp.RequestCtx) bool
|
CheckOrigin(ctx *fasthttp.RequestCtx) bool
|
||||||
OnError(ctx *fasthttp.RequestCtx, status int, reason error)
|
OnError(ctx *fasthttp.RequestCtx, status int, reason error)
|
||||||
|
// OnStop invoked when server is stopped
|
||||||
OnStart() error
|
// If you override ths method, must call
|
||||||
|
//
|
||||||
|
// func (sh *ServerHandler) OnStop() {
|
||||||
|
// ...
|
||||||
|
// sh.ServerHandler.OnStop()
|
||||||
|
// }
|
||||||
OnStop()
|
OnStop()
|
||||||
|
|
||||||
RegisterSocketHandler(path string, handler SocketHandler)
|
RegisterSocketHandler(path string, handler SocketHandler)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user