mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
internal/server/server.go: Implement options using the functional pattern.
This commit is contained in:
parent
6b561bdf25
commit
6030981ba5
2 changed files with 18 additions and 5 deletions
|
|
@ -181,7 +181,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
srv = server.New(argv_listen_addr(), time.Second*10)
|
srv = server.New(argv_listen_addr(), server.WithTick(time.Second*10))
|
||||||
|
|
||||||
// Run signal event loop in its own goroutine
|
// Run signal event loop in its own goroutine
|
||||||
go signalEventLoop()
|
go signalEventLoop()
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,23 @@ type Server struct {
|
||||||
tick_interval time.Duration
|
tick_interval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(addr string, tick_interval time.Duration) *Server {
|
type Option func(*Server)
|
||||||
return &Server{
|
|
||||||
addr: fmt.Sprintf("tcp://%s", addr),
|
func New(addr string, options ...Option) *Server {
|
||||||
tick_interval: tick_interval,
|
s := &Server{
|
||||||
|
addr: fmt.Sprintf("tcp://%s", addr),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range options {
|
||||||
|
opt(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithTick(interval time.Duration) Option {
|
||||||
|
return func(s *Server) {
|
||||||
|
s.tick_interval = interval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue