server-go/client-conn-handler.go
crusader acbc1b22be ing
2018-04-04 22:50:34 +09:00

43 lines
778 B
Go

package server
import (
"time"
)
type ClientConnHandler interface {
ConnectionHandler
GetReconnectInterval() time.Duration
GetReconnectTryTime() int
}
type ClientConnHandlers struct {
ConnectionHandlers
ReconnectInterval time.Duration
ReconnectTryTime int
}
func (cch *ClientConnHandlers) GetReconnectInterval() time.Duration {
return cch.ReconnectInterval
}
func (cch *ClientConnHandlers) GetReconnectTryTime() int {
return cch.ReconnectTryTime
}
func (cch *ClientConnHandlers) Validate() error {
if err := cch.ConnectionHandlers.Validate(); nil != err {
return err
}
if cch.ReconnectInterval <= 0 {
cch.ReconnectInterval = DefaultReconnectInterval
}
if cch.ReconnectTryTime <= 0 {
cch.ReconnectTryTime = DefaultReconnectTryTime
}
return nil
}