diff options
Diffstat (limited to 'http/service.go')
-rw-r--r-- | http/service.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/http/service.go b/http/service.go index 81ffb8a2..7835a652 100644 --- a/http/service.go +++ b/http/service.go @@ -18,24 +18,21 @@ type Middleware interface { // Service manages rr, http servers. type Service struct { - cfg *Config - - // todo: multiple listeners - listener func(event int, ctx interface{}) - + cfg *Config + listeners []func(event int, ctx interface{}) middleware []Middleware rr *roadrunner.Server srv *Server http *http.Server } -func (s *Service) Add(m Middleware) { +func (s *Service) AddMiddleware(m Middleware) { s.middleware = append(s.middleware, m) } -// Listen attaches server event watcher. -func (s *Service) Listen(o func(event int, ctx interface{})) { - s.listener = o +// AddListener attaches server event watcher. +func (s *Service) AddListener(l func(event int, ctx interface{})) { + s.listeners = append(s.listeners, l) } // Configure must return configure svc and return true if svc hasStatus enabled. Must return error in case of @@ -114,3 +111,9 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.srv.ServeHTTP(w, r) } + +func (s *Service) listener(event int, ctx interface{}) { + for _, l := range s.listeners { + l(event, ctx) + } +} |