package server import ( "fmt" "net" "reflect" "go.uber.org/zap" olog "git.loafle.net/overflow/log-go" "git.loafle.net/overflow/server-go" ossw "git.loafle.net/overflow/server-go/socket/web" ) type ServerHandler interface { ossw.ServerHandler } type ServerHandlers struct { ossw.ServerHandlers Services []interface{} OrderedServices []reflect.Type } func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error { if err := sh.ServerHandlers.Init(serverCtx); nil != err { return err } return nil } func (sh *ServerHandlers) OnStart(serverCtx server.ServerCtx) error { if err := sh.ServerHandlers.OnStart(serverCtx); nil != err { return err } return nil } func (sh *ServerHandlers) OnStop(serverCtx server.ServerCtx) { sh.ServerHandlers.OnStop(serverCtx) } func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) { sh.ServerHandlers.Destroy(serverCtx) } func (sh *ServerHandlers) Listener(serverCtx server.ServerCtx) (net.Listener, error) { for i := 60000; i < 61000; i++ { addr := fmt.Sprintf("localhost:%d", i) l, err := net.Listen("tcp", addr) if nil == err { olog.Logger().Debug("Listener", zap.Int("port", i)) // config.ProbePortNumber = int64(i) return l, nil } } return nil, fmt.Errorf("Cannot find availrable port") } func (sh *ServerHandlers) Validate() error { if err := sh.ServerHandlers.Validate(); nil != err { return err } if nil == sh.Services { return fmt.Errorf("Services must be specified") } if nil == sh.OrderedServices { return fmt.Errorf("OrderedServices must be specified") } return nil }