-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
75 lines (58 loc) · 1.54 KB
/
config.go
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
75
package centrifuge
import (
"os"
"github.com/roadrunner-server/errors"
"github.com/roadrunner-server/pool/pool"
)
type Config struct {
// host + port
ProxyAddress string `mapstructure:"proxy_address"`
// host + port
GrpcAPIAddress string `mapstructure:"grpc_api_address"`
UseCompressor bool `mapstructure:"use_compressor"`
Version string `mapstructure:"version"`
Name string `mapstructure:"name"`
TLS *TLS `mapstructure:"tls"`
Pool *pool.Config `mapstructure:"pool"`
}
type TLS struct {
Key string `mapstructure:"key"`
Cert string `mapstructure:"cert"`
}
func (c *Config) InitDefaults() error {
const op = errors.Op("centrifuge_init_defaults")
if c.GrpcAPIAddress == "" {
c.GrpcAPIAddress = "127.0.0.1:10000"
}
if len(c.GrpcAPIAddress) > 7 && c.GrpcAPIAddress[0:6] == "tcp://" {
c.GrpcAPIAddress = c.GrpcAPIAddress[6:]
}
if c.ProxyAddress == "" {
c.ProxyAddress = "tcp://127.0.0.1:30000"
}
if c.Name == "" {
c.Name = "roadrunner"
}
if c.Version == "" {
c.Version = "1.0.0"
}
if c.Pool == nil {
c.Pool = &pool.Config{}
}
c.Pool.InitDefaults()
if c.TLS != nil { //nolint:nestif
if _, err := os.Stat(c.TLS.Key); err != nil {
if os.IsNotExist(err) {
return errors.E(op, errors.Errorf("key file '%s' does not exists", c.TLS.Key))
}
return errors.E(op, err)
}
if _, err := os.Stat(c.TLS.Cert); err != nil {
if os.IsNotExist(err) {
return errors.E(op, errors.Errorf("cert file '%s' does not exists", c.TLS.Cert))
}
return errors.E(op, err)
}
}
return nil
}