summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-23 15:00:51 +0300
committerWolfy-J <[email protected]>2018-09-23 15:00:51 +0300
commit46c53d51cd8edd4e934c47f49f806758f4ccad63 (patch)
tree5e04c41ebb1b8eba5713c992c3d4866e8fb959fb
parent19d88fc879ba403347726138eb532fb85d38168e (diff)
default configs
-rw-r--r--config.go9
-rw-r--r--server_config.go9
-rw-r--r--server_config_test.go2
-rw-r--r--service/http/config.go34
-rw-r--r--service/http/service.go4
-rw-r--r--service/http/uploads_config.go6
6 files changed, 22 insertions, 42 deletions
diff --git a/config.go b/config.go
index 82f05ca3..23f1afc8 100644
--- a/config.go
+++ b/config.go
@@ -27,13 +27,8 @@ type Config struct {
// InitDefaults allows to init blank config with pre-defined set of default values.
func (cfg *Config) InitDefaults() error {
- if cfg.AllocateTimeout == 0 {
- cfg.AllocateTimeout = time.Minute
- }
-
- if cfg.DestroyTimeout == 0 {
- cfg.DestroyTimeout = time.Minute
- }
+ cfg.AllocateTimeout = time.Minute
+ cfg.DestroyTimeout = time.Minute
return nil
}
diff --git a/server_config.go b/server_config.go
index b2d8845b..936744a1 100644
--- a/server_config.go
+++ b/server_config.go
@@ -35,13 +35,8 @@ type ServerConfig struct {
// InitDefaults sets missing values to their default values.
func (cfg *ServerConfig) InitDefaults() error {
- if cfg.Relay == "" {
- cfg.Relay = "pipes"
- }
-
- if cfg.RelayTimeout == 0 {
- cfg.RelayTimeout = time.Minute
- }
+ cfg.Relay = "pipes"
+ cfg.RelayTimeout = time.Minute
if cfg.Pool == nil {
cfg.Pool = &Config{}
diff --git a/server_config_test.go b/server_config_test.go
index ec29412e..532ea4f9 100644
--- a/server_config_test.go
+++ b/server_config_test.go
@@ -129,7 +129,7 @@ func Test_Config_Upscale(t *testing.T) {
},
}
- cfg.UpscaleDurations()
+ cfg.Pool.UpscaleDurations()
assert.Equal(t, time.Second, cfg.RelayTimeout)
assert.Equal(t, time.Second, cfg.Pool.AllocateTimeout)
assert.Equal(t, time.Second, cfg.Pool.DestroyTimeout)
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 != "" {