1
0
Fork 0
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:
Henrik Hautakoski 2023-02-07 09:11:17 +01:00
parent 6b561bdf25
commit 6030981ba5
No known key found for this signature in database
GPG key ID: 217490840C18A5D9
2 changed files with 18 additions and 5 deletions

View file

@ -181,7 +181,7 @@ func main() {
}
// 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
go signalEventLoop()

View file

@ -28,10 +28,23 @@ type Server struct {
tick_interval time.Duration
}
func New(addr string, tick_interval time.Duration) *Server {
return &Server{
type Option func(*Server)
func New(addr string, options ...Option) *Server {
s := &Server{
addr: fmt.Sprintf("tcp://%s", addr),
tick_interval: tick_interval,
}
for _, opt := range options {
opt(s)
}
return s
}
func WithTick(interval time.Duration) Option {
return func(s *Server) {
s.tick_interval = interval
}
}