summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-23 13:50:12 +0300
committerWolfy-J <[email protected]>2018-09-23 13:50:12 +0300
commit897fa09e144e6ff4d6213346eef917c7112d75e0 (patch)
tree1fcd425e2c7c9f1bdbcc8ac3c3b44e7a4d4b5a77 /service
parentbdff4b25d2a879357bc0ed53e96c0b551de07f88 (diff)
improved server stopping mechanism
Diffstat (limited to 'service')
-rw-r--r--service/http/service.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/service/http/service.go b/service/http/service.go
index ecce1c15..94524897 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -24,20 +24,20 @@ type middleware func(f http.HandlerFunc) http.HandlerFunc
// Service manages rr, http servers.
type Service struct {
- cfg *Config
- env env.Environment
- lsns []func(event int, ctx interface{})
- mdws []middleware
- mu sync.Mutex
- rr *roadrunner.Server
- stopping int32
- srv *Handler
- http *http.Server
+ cfg *Config
+ env env.Environment
+ lsns []func(event int, ctx interface{})
+ middleware []middleware
+ mu sync.Mutex
+ rr *roadrunner.Server
+ stopping int32
+ srv *Handler
+ http *http.Server
}
// AddMiddleware adds new net/http middleware.
func (s *Service) AddMiddleware(m middleware) {
- s.mdws = append(s.mdws, m)
+ s.middleware = append(s.middleware, m)
}
// AddListener attaches server event watcher.
@@ -87,7 +87,7 @@ func (s *Service) Serve() error {
s.rr.Listen(s.listener)
s.srv.Listen(s.listener)
- if len(s.mdws) == 0 {
+ if len(s.middleware) == 0 {
s.http.Handler = s.srv
} else {
s.http.Handler = s
@@ -97,7 +97,7 @@ func (s *Service) Serve() error {
if err := rr.Start(); err != nil {
return err
}
- defer s.rr.Stop()
+ defer rr.Stop()
return s.http.ListenAndServe()
}
@@ -118,13 +118,13 @@ func (s *Service) Stop() {
s.http.Shutdown(context.Background())
}
-// middleware handles connection using set of mdws and rr PSR-7 server.
+// middleware handles connection using set of middleware and rr PSR-7 server.
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r = attributes.Init(r)
- // chaining middlewares
+ // chaining middleware
f := s.srv.ServeHTTP
- for _, m := range s.mdws {
+ for _, m := range s.middleware {
f = m(f)
}
f(w, r)