server-go/server-handler.go

66 lines
1.1 KiB
Go
Raw Normal View History

2018-04-03 08:55:48 +00:00
package server
type ServerHandler interface {
2018-04-04 13:28:35 +00:00
ConnectionHandler
ReadWriteHandler
2018-04-03 08:55:48 +00:00
2018-04-04 13:28:35 +00:00
GetName() string
2018-04-04 04:01:26 +00:00
ServerCtx() ServerCtx
2018-04-03 08:55:48 +00:00
2018-04-04 04:01:26 +00:00
Init(serverCtx ServerCtx) error
OnStart(serverCtx ServerCtx) error
OnStop(serverCtx ServerCtx)
Destroy(serverCtx ServerCtx)
2018-04-03 08:55:48 +00:00
2018-04-04 04:01:26 +00:00
Validate() error
2018-04-03 08:55:48 +00:00
}
type ServerHandlers struct {
2018-04-04 13:28:35 +00:00
ConnectionHandlers
ReadWriteHandlers
2018-04-03 08:55:48 +00:00
2018-04-04 04:01:26 +00:00
// Server name for sending in response headers.
//
// Default server name is used if left blank.
Name string
2018-04-03 08:55:48 +00:00
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) ServerCtx() ServerCtx {
2018-04-04 06:35:07 +00:00
return NewServerCtx(nil)
2018-04-03 08:55:48 +00:00
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) Init(serverCtx ServerCtx) error {
2018-04-03 08:55:48 +00:00
return nil
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) OnStart(serverCtx ServerCtx) error {
2018-04-03 08:55:48 +00:00
return nil
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) OnStop(serverCtx ServerCtx) {
2018-04-03 08:55:48 +00:00
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) Destroy(serverCtx ServerCtx) {
2018-04-03 08:55:48 +00:00
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) GetName() string {
return sh.Name
2018-04-03 08:55:48 +00:00
}
2018-04-04 04:01:26 +00:00
func (sh *ServerHandlers) Validate() error {
2018-04-04 13:28:35 +00:00
if err := sh.ConnectionHandlers.Validate(); nil != err {
return err
2018-04-03 08:55:48 +00:00
}
2018-04-04 13:28:35 +00:00
if err := sh.ReadWriteHandlers.Validate(); nil != err {
return err
2018-04-04 04:01:26 +00:00
}
2018-04-04 13:28:35 +00:00
if "" == sh.Name {
sh.Name = "Server"
2018-04-04 04:01:26 +00:00
}
return nil
2018-04-03 08:55:48 +00:00
}