diff options
Diffstat (limited to 'service/http/service.go')
-rw-r--r-- | service/http/service.go | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/service/http/service.go b/service/http/service.go index 710cd60c..f7fdf2ab 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -3,7 +3,7 @@ package http import ( "context" "github.com/spiral/roadrunner" - "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/service/http/attributes" "github.com/spiral/roadrunner/service/rpc" "net/http" "sync" @@ -41,28 +41,14 @@ func (s *Service) AddListener(l func(event int, ctx interface{})) { // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. -func (s *Service) Init(cfg service.Config, c service.Container) (bool, error) { - config := &Config{} - - if err := cfg.Unmarshal(config); err != nil { - return false, err - } - - if !config.Enable { +func (s *Service) Init(cfg *Config, r *rpc.Service) (bool, error) { + if !cfg.Enable { return false, nil } - if err := config.Valid(); err != nil { - return false, err - } - - s.cfg = config - - // registering http RPC interface - if r, ok := c.Get(rpc.ID); ok >= service.StatusConfigured { - if h, ok := r.(*rpc.Service); ok { - h.Register(ID, &rpcServer{s}) - } + s.cfg = cfg + if r != nil { + r.Register(ID, &rpcServer{s}) } return true, nil @@ -113,16 +99,17 @@ func (s *Service) Stop() { // middleware handles connection using set of mdws and rr PSR-7 server. func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { - r = InitAttributes(r) + r = attributes.Init(r) + // chaining middlewares f := s.srv.ServeHTTP for _, m := range s.mdws { f = m(f) } - f(w, r) } +// listener handles service, server and pool events. func (s *Service) listener(event int, ctx interface{}) { for _, l := range s.lsns { l(event, ctx) |