summaryrefslogtreecommitdiff
path: root/service/static/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-08 13:06:05 -0700
committerWolfy-J <[email protected]>2018-07-08 13:06:05 -0700
commit29c9bf94350e86ec96f5ce5eeb476dfcd57302cd (patch)
tree9f59af6446958d144b7de91b5005a3727dc90661 /service/static/service.go
parent3c3a7801100f29c99a5e446646c818bf16ccd5f0 (diff)
dependency injection and lighter service Init methods.
Diffstat (limited to 'service/static/service.go')
-rw-r--r--service/static/service.go30
1 files changed, 4 insertions, 26 deletions
diff --git a/service/static/service.go b/service/static/service.go
index add242e4..968cb594 100644
--- a/service/static/service.go
+++ b/service/static/service.go
@@ -1,7 +1,6 @@
package static
import (
- "github.com/spiral/roadrunner/service"
rrttp "github.com/spiral/roadrunner/service/http"
"net/http"
"path"
@@ -22,39 +21,18 @@ type Service struct {
// Init must return configure service and return true if service 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) (enabled bool, err error) {
- config := &Config{}
- if err := cfg.Unmarshal(config); err != nil {
- return false, err
- }
-
- if !config.Enable {
+func (s *Service) Init(cfg *Config, r *rrttp.Service) (enabled bool, err error) {
+ if !cfg.Enable || r == nil {
return false, nil
}
- if err := config.Valid(); err != nil {
- return false, err
- }
-
- s.cfg = config
+ s.cfg = cfg
s.root = http.Dir(s.cfg.Dir)
-
- // registering as middleware
- if h, ok := c.Get(rrttp.ID); ok >= service.StatusConfigured {
- if h, ok := h.(*rrttp.Service); ok {
- h.AddMiddleware(s.middleware)
- }
- }
+ r.AddMiddleware(s.middleware)
return true, nil
}
-// Serve serves the service.
-func (s *Service) Serve() error { return nil }
-
-// Stop stops the service.
-func (s *Service) Stop() {}
-
// middleware must return true if request/response pair is handled within the middleware.
func (s *Service) middleware(f http.HandlerFunc) http.HandlerFunc {
// Define the http.HandlerFunc