diff --git a/servlet.go b/servlet.go index 724b075..d67adab 100644 --- a/servlet.go +++ b/servlet.go @@ -4,5 +4,7 @@ type Servlet interface { ServletCtx(serverCtx ServerCtx) ServletCtx Init(serverCtx ServerCtx) error + OnStart(serverCtx ServerCtx) error + OnStop(serverCtx ServerCtx) Destroy(serverCtx ServerCtx) } diff --git a/socket/net/server-handler.go b/socket/net/server-handler.go index ca757b3..40939eb 100644 --- a/socket/net/server-handler.go +++ b/socket/net/server-handler.go @@ -36,6 +36,28 @@ func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error { return nil } +func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error { + if err := sh.ServerHandlers.OnStart(serverCtx); nil != err { + return err + } + + if nil != sh.servlet { + if err := sh.servlet.OnStart(serverCtx); nil != err { + return err + } + } + + return nil +} + +func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) { + if nil != sh.servlet { + sh.servlet.OnStop(serverCtx) + } + + sh.ServerHandlers.OnStop(serverCtx) +} + func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) { if nil != sh.servlet { sh.servlet.Destroy(serverCtx) diff --git a/socket/net/servlet.go b/socket/net/servlet.go index 3299fd2..fdd12f6 100644 --- a/socket/net/servlet.go +++ b/socket/net/servlet.go @@ -25,6 +25,14 @@ func (s *Servlets) Init(serverCtx server.ServerCtx) error { return nil } +func (s *Servlets) OnStart(serverCtx server.ServerCtx) error { + return nil +} + +func (s *Servlets) OnStop(serverCtx server.ServerCtx) { + // +} + func (s *Servlets) Destroy(serverCtx server.ServerCtx) { // } diff --git a/socket/readwrite-handler.go b/socket/readwrite-handler.go index de8abc2..958513a 100644 --- a/socket/readwrite-handler.go +++ b/socket/readwrite-handler.go @@ -18,11 +18,11 @@ type ReadWriteHandler interface { type ReadWriteHandlers struct { server.ReadWriteHandlers - PongTimeout time.Duration `json:"pongTimeout"` - PingTimeout time.Duration `json:"pingTimeout"` - PingPeriod time.Duration `json:"pingPeriod"` + PongTimeout time.Duration `json:"pongTimeout"` + PingTimeout time.Duration `json:"pingTimeout"` + PingPeriod time.Duration `json:"pingPeriod"` - EnableCompression bool `json:"enableCompression"` + EnableCompression bool `json:"enableCompression"` } func (rwh *ReadWriteHandlers) GetPongTimeout() time.Duration { diff --git a/socket/web/server-handler.go b/socket/web/server-handler.go index d72a6c4..ee3718f 100644 --- a/socket/web/server-handler.go +++ b/socket/web/server-handler.go @@ -42,6 +42,32 @@ func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error { return nil } +func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error { + if err := sh.ServerHandlers.OnStart(serverCtx); nil != err { + return err + } + + if nil != sh.servlets { + for _, servlet := range sh.servlets { + if err := servlet.OnStart(serverCtx); nil != err { + return err + } + } + } + + return nil +} + +func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) { + if nil != sh.servlets { + for _, servlet := range sh.servlets { + servlet.OnStop(serverCtx) + } + } + + sh.ServerHandlers.OnStop(serverCtx) +} + func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) { if nil != sh.servlets { for _, servlet := range sh.servlets { diff --git a/socket/web/servlet.go b/socket/web/servlet.go index 964aee0..6d6bd27 100644 --- a/socket/web/servlet.go +++ b/socket/web/servlet.go @@ -24,6 +24,14 @@ func (s *Servlets) Init(serverCtx server.ServerCtx) error { return nil } +func (s *Servlets) OnStart(serverCtx server.ServerCtx) error { + return nil +} + +func (s *Servlets) OnStop(serverCtx server.ServerCtx) { + // +} + func (s *Servlets) Destroy(serverCtx server.ServerCtx) { // } diff --git a/web/fasthttp/server-handler.go b/web/fasthttp/server-handler.go index 37d8986..4693f6f 100644 --- a/web/fasthttp/server-handler.go +++ b/web/fasthttp/server-handler.go @@ -48,6 +48,32 @@ func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error { return nil } +func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error { + if err := sh.ServerHandlers.OnStart(serverCtx); nil != err { + return err + } + + if nil != sh.servlets { + for _, servlet := range sh.servlets { + if err := servlet.OnStart(serverCtx); nil != err { + return err + } + } + } + + return nil +} + +func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) { + if nil != sh.servlets { + for _, servlet := range sh.servlets { + servlet.OnStop(serverCtx) + } + } + + sh.ServerHandlers.OnStop(serverCtx) +} + func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) { if nil != sh.servlets { for _, servlet := range sh.servlets { diff --git a/web/fasthttp/servlet.go b/web/fasthttp/servlet.go index 720b9d3..55c944c 100644 --- a/web/fasthttp/servlet.go +++ b/web/fasthttp/servlet.go @@ -24,6 +24,14 @@ func (s *Servlets) Init(serverCtx server.ServerCtx) error { return nil } +func (s *Servlets) OnStart(serverCtx server.ServerCtx) error { + return nil +} + +func (s *Servlets) OnStop(serverCtx server.ServerCtx) { + // +} + func (s *Servlets) Destroy(serverCtx server.ServerCtx) { // }