diff options
author | Wolfy-J <[email protected]> | 2018-07-08 22:04:18 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2018-07-08 22:04:18 -0700 |
commit | 47ae9f40b2ead4656bec9ea1204e5c8936cab76c (patch) | |
tree | 0d3aad39c0ea1ac697b61047ebf505f69275ba54 /service/http/config.go | |
parent | ad0562981de801ad32b5bfd48cea9c92793a8cc0 (diff) | |
parent | 21bd058003a159ff307565d5b57e3631921a7a96 (diff) |
Merge pull request #28 from spiral/feature/arguments
v1.1.0
Diffstat (limited to 'service/http/config.go')
-rw-r--r-- | service/http/config.go | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/service/http/config.go b/service/http/config.go index 19a2e71d..20a247fb 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -3,7 +3,9 @@ package http import ( "errors" "github.com/spiral/roadrunner" + "github.com/spiral/roadrunner/service" "strings" + "time" ) // Config configures RoadRunner HTTP server. @@ -24,25 +26,54 @@ type Config struct { Workers *roadrunner.ServerConfig } +// 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 err := c.Valid(); err != nil { + return err + } + + if c.Workers.Relay == "" { + c.Workers.Relay = "pipes" + } + + if c.Workers.RelayTimeout < time.Microsecond { + c.Workers.RelayTimeout = time.Second * time.Duration(c.Workers.RelayTimeout.Nanoseconds()) + } + + if c.Workers.Pool.AllocateTimeout < time.Microsecond { + c.Workers.Pool.AllocateTimeout = time.Second * time.Duration(c.Workers.Pool.AllocateTimeout.Nanoseconds()) + } + + if c.Workers.Pool.DestroyTimeout < time.Microsecond { + c.Workers.Pool.DestroyTimeout = time.Second * time.Duration(c.Workers.Pool.DestroyTimeout.Nanoseconds()) + } + + return nil +} + // Valid validates the configuration. -func (cfg *Config) Valid() error { - if cfg.Uploads == nil { +func (c *Config) Valid() error { + if c.Uploads == nil { return errors.New("mailformed uploads config") } - if cfg.Workers == nil { + if c.Workers == nil { return errors.New("mailformed workers config") } - if cfg.Workers.Pool == nil { + if c.Workers.Pool == nil { return errors.New("mailformed workers config (pool config is missing)") } - if err := cfg.Workers.Pool.Valid(); err != nil { + if err := c.Workers.Pool.Valid(); err != nil { return err } - if !strings.Contains(cfg.Address, ":") { + if !strings.Contains(c.Address, ":") { return errors.New("mailformed server address") } |