overflow_discovery/server/server_handlers.go

57 lines
1.0 KiB
Go
Raw Normal View History

2017-10-26 12:55:55 +00:00
package server
import (
2017-11-15 06:59:43 +00:00
"fmt"
2017-10-26 12:55:55 +00:00
2017-11-15 06:59:43 +00:00
"git.loafle.net/commons_go/logging"
2017-11-15 12:09:38 +00:00
"git.loafle.net/overflow/overflow_discovery/discovery"
2017-11-15 06:59:43 +00:00
"git.loafle.net/commons_go/server"
2017-10-26 12:55:55 +00:00
)
2017-11-29 05:19:36 +00:00
func newServerHandler(addr string, socketHandler SocketHandler) ServerHandler {
2017-11-15 06:59:43 +00:00
sh := &ServerHandlers{
2017-11-29 05:19:36 +00:00
addr: addr,
2017-11-15 06:59:43 +00:00
}
2017-11-01 06:35:03 +00:00
2017-11-29 05:19:36 +00:00
sh.Name = "Discovery"
sh.SocketHandler = socketHandler
2017-10-26 12:55:55 +00:00
return sh
}
type ServerHandlers struct {
2017-11-01 06:35:03 +00:00
server.ServerHandlers
2017-10-26 12:55:55 +00:00
2017-11-29 05:19:36 +00:00
addr string
2017-11-15 06:59:43 +00:00
}
2017-11-29 05:19:36 +00:00
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
if err := sh.ServerHandlers.Init(serverCTX); nil != err {
return err
2017-11-15 06:59:43 +00:00
}
2017-11-23 09:34:07 +00:00
2017-11-29 05:19:36 +00:00
return nil
2017-11-15 06:59:43 +00:00
}
2017-11-29 05:19:36 +00:00
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
sh.ServerHandlers.OnStart(serverCTX)
2017-11-29 00:36:19 +00:00
2017-11-29 05:19:36 +00:00
discovery.DiscoveryInit()
2017-11-15 06:59:43 +00:00
}
2017-11-29 05:19:36 +00:00
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
2017-11-23 09:34:07 +00:00
2017-11-15 12:09:38 +00:00
discovery.DiscoveryDestroy()
2017-11-29 05:19:36 +00:00
sh.ServerHandlers.OnStop(serverCTX)
2017-11-01 06:35:03 +00:00
}
2017-10-26 13:18:20 +00:00
2017-11-15 06:59:43 +00:00
func (sh *ServerHandlers) Validate() {
sh.ServerHandlers.Validate()
if "" == sh.addr {
logging.Logger().Panic(fmt.Sprintf("Server: Address of server must be specified"))
2017-10-26 13:18:20 +00:00
}
2017-11-01 06:35:03 +00:00
2017-11-29 00:36:19 +00:00
}