server-go/server-handler.go

61 lines
1.0 KiB
Go
Raw Normal View History

2018-04-03 08:55:48 +00:00
package server
type ServerHandler interface {
2018-04-06 11:47:32 +00:00
ConnectionHandler
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-06 11:47:32 +00:00
ConnectionHandlers
2018-04-04 04:01:26 +00:00
// Server name for sending in response headers.
//
// Default server name is used if left blank.
2018-04-09 12:11:52 +00:00
Name string `json:"name"`
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-06 11:47:32 +00:00
if err := sh.ConnectionHandlers.Validate(); nil != err {
return err
}
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
}