diff options
author | Wolfy-J <[email protected]> | 2018-09-23 15:00:51 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-23 15:00:51 +0300 |
commit | 46c53d51cd8edd4e934c47f49f806758f4ccad63 (patch) | |
tree | 5e04c41ebb1b8eba5713c992c3d4866e8fb959fb /service | |
parent | 19d88fc879ba403347726138eb532fb85d38168e (diff) |
default configs
Diffstat (limited to 'service')
-rw-r--r-- | service/http/config.go | 34 | ||||
-rw-r--r-- | service/http/service.go | 4 | ||||
-rw-r--r-- | service/http/uploads_config.go | 6 |
3 files changed, 17 insertions, 27 deletions
diff --git a/service/http/config.go b/service/http/config.go index 321072c5..26cede37 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -9,9 +9,6 @@ import ( // Config configures RoadRunner HTTP server. type Config struct { - // Enable enables http service. - Enable bool - // Address and port to handle as http server. Address string @@ -27,41 +24,32 @@ type Config struct { // Hydrate must populate Config values using given Config source. Must return error if Config is not valid. func (c *Config) Hydrate(cfg service.Config) error { - if err := cfg.Unmarshal(c); err != nil { - return err + if c.Workers == nil { + c.Workers = &roadrunner.ServerConfig{} } - if !c.Enable { - return nil + if c.Uploads == nil { + c.Uploads = &UploadsConfig{} } - if c.Workers != nil { - c.Workers.InitDefaults() - } + c.Uploads.InitDefaults() + c.Workers.InitDefaults() - if err := c.Valid(); err != nil { + if err := cfg.Unmarshal(c); err != nil { return err } c.Workers.UpscaleDurations() + if err := c.Valid(); err != nil { + return err + } + return nil } // Valid validates the configuration. func (c *Config) Valid() error { - if c.Uploads == nil { - return errors.New("mailformed uploads config") - } - - if c.Workers == nil { - return errors.New("mailformed workers config") - } - - if c.Workers.Pool == nil { - return errors.New("mailformed workers config (pool config is missing)") - } - if err := c.Workers.Pool.Valid(); err != nil { return err } diff --git a/service/http/service.go b/service/http/service.go index 6bf6e33f..679a6cd9 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -48,10 +48,6 @@ 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 *Config, r *rpc.Service, e env.Environment) (bool, error) { - if !cfg.Enable { - return false, nil - } - s.cfg = cfg s.env = e if r != nil { diff --git a/service/http/uploads_config.go b/service/http/uploads_config.go index e90d9b70..3f655064 100644 --- a/service/http/uploads_config.go +++ b/service/http/uploads_config.go @@ -16,6 +16,12 @@ type UploadsConfig struct { Forbid []string } +// InitDefaults sets missing values to their default values. +func (cfg *UploadsConfig) InitDefaults() error { + cfg.Forbid = []string{".php", ".exe", ".bat"} + return nil +} + // TmpDir returns temporary directory. func (cfg *UploadsConfig) TmpDir() string { if cfg.Dir != "" { |