diff options
author | Wolfy-J <[email protected]> | 2018-06-13 14:07:58 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-13 14:07:58 +0300 |
commit | 7d77b05901f4b34025a307de2ac4a83ae3162452 (patch) | |
tree | 847574125797cb69d444530cbae59cf345cbe415 /service | |
parent | ca95f67317bcf8972b9e669869338a7dc09bf06d (diff) |
minor refactor
Diffstat (limited to 'service')
-rw-r--r-- | service/http/handler.go | 2 | ||||
-rw-r--r-- | service/http/service.go | 10 | ||||
-rw-r--r-- | service/static/service.go | 8 |
3 files changed, 9 insertions, 11 deletions
diff --git a/service/http/handler.go b/service/http/handler.go index 0124a2a4..a4cb6406 100644 --- a/service/http/handler.go +++ b/service/http/handler.go @@ -48,7 +48,7 @@ func (h *Handler) Listen(l func(event int, ctx interface{})) { h.lsn = l } -// Handle serve using PSR-7 requests passed to underlying application. Attempts to serve static files first if enabled. +// middleware serve using PSR-7 requests passed to underlying application. Attempts to serve static files first if enabled. func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // validating request size if h.cfg.MaxRequest != 0 { diff --git a/service/http/service.go b/service/http/service.go index f1712fd2..881c862d 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -11,10 +11,8 @@ import ( // Name contains default svc name. const Name = "http" -type middleware interface { - // Handle must return true if request/response pair is handled withing the mdws. - Handle(w http.ResponseWriter, r *http.Request) bool -} +// must return true if request/response pair is handled withing the middleware. +type middleware func(w http.ResponseWriter, r *http.Request) bool // Service manages rr, http servers. type Service struct { @@ -101,10 +99,10 @@ func (s *Service) Stop() { s.http.Shutdown(context.Background()) } -// Handle handles connection using set of mdws and rr PSR-7 server. +// middleware handles connection using set of mdws and rr PSR-7 server. func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { for _, m := range s.mdws { - if m.Handle(w, r) { + if m(w, r) { return } } diff --git a/service/static/service.go b/service/static/service.go index 5f7d31f0..8d383fcf 100644 --- a/service/static/service.go +++ b/service/static/service.go @@ -42,7 +42,7 @@ func (s *Service) Init(cfg service.Config, c service.Container) (enabled bool, e // registering as middleware if h, ok := c.Get(rrttp.Name); ok >= service.StatusConfigured { if h, ok := h.(*rrttp.Service); ok { - h.AddMiddleware(s) + h.AddMiddleware(s.middleware) } } @@ -55,8 +55,8 @@ func (s *Service) Serve() error { return nil } // Stop stops the service. func (s *Service) Stop() {} -// Handle must return true if request/response pair is handled withing the middleware. -func (s *Service) Handle(w http.ResponseWriter, r *http.Request) bool { +// middleware must return true if request/response pair is handled withing the middleware. +func (s *Service) middleware(w http.ResponseWriter, r *http.Request) bool { fPath := r.URL.Path if !strings.HasPrefix(fPath, "/") { fPath = "/" + fPath @@ -78,7 +78,7 @@ func (s *Service) Handle(w http.ResponseWriter, r *http.Request) bool { return false } - // do not Handle directories + // do not middleware directories if d.IsDir() { return false } |