server-go/server-handler.go
crusader 7e7d6258c0 ing
2018-04-06 00:15:29 +09:00

53 lines
905 B
Go

package server
type ServerHandler interface {
GetName() string
ServerCtx() ServerCtx
Init(serverCtx ServerCtx) error
OnStart(serverCtx ServerCtx) error
OnStop(serverCtx ServerCtx)
Destroy(serverCtx ServerCtx)
Validate() error
}
type ServerHandlers struct {
// Server name for sending in response headers.
//
// Default server name is used if left blank.
Name string
}
func (sh *ServerHandlers) ServerCtx() ServerCtx {
return NewServerCtx(nil)
}
func (sh *ServerHandlers) Init(serverCtx ServerCtx) error {
return nil
}
func (sh *ServerHandlers) OnStart(serverCtx ServerCtx) error {
return nil
}
func (sh *ServerHandlers) OnStop(serverCtx ServerCtx) {
}
func (sh *ServerHandlers) Destroy(serverCtx ServerCtx) {
}
func (sh *ServerHandlers) GetName() string {
return sh.Name
}
func (sh *ServerHandlers) Validate() error {
if "" == sh.Name {
sh.Name = "Server"
}
return nil
}