go-peer/pkg/network/connkeeper/settings.go
2024-02-02 09:51:42 +07:00

39 lines
672 B
Go

package connkeeper
import "time"
var (
_ ISettings = &sSettings{}
)
type SSettings sSettings
type sSettings struct {
FConnections func() []string
FDuration time.Duration
}
func NewSettings(pSett *SSettings) ISettings {
return (&sSettings{
FConnections: pSett.FConnections,
FDuration: pSett.FDuration,
}).mustNotNull()
}
func (p *sSettings) mustNotNull() ISettings {
if p.FDuration == 0 {
panic(`p.FDuration = cDuration`)
}
if p.FConnections == nil {
panic(`p.FConnections == nil`)
}
return p
}
func (p *sSettings) GetConnections() []string {
return p.FConnections()
}
func (p *sSettings) GetDuration() time.Duration {
return p.FDuration
}