blob: b11d807c9b21ee2fe530ca65db651361cf3054b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package http
import (
"errors"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
"strings"
)
// Config configures RoadRunner HTTP server.
type Config struct {
// Address and port to handle as http server.
Address string
// MaxRequest specified max size for payload body in megabytes, set 0 to unlimited.
MaxRequest int64
// Uploads configures uploads configuration.
Uploads *UploadsConfig
// Workers configures roadrunner server and worker pool.
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 c.Workers == nil {
c.Workers = &roadrunner.ServerConfig{}
}
if c.Uploads == nil {
c.Uploads = &UploadsConfig{}
}
c.Uploads.InitDefaults()
c.Workers.InitDefaults()
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
}
if !strings.Contains(c.Address, ":") {
return errors.New("mailformed server address")
}
return nil
}
|