-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
136 lines (111 loc) · 3.5 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package thumper
import (
"github.com/roadrunner-server/config/v4"
"github.com/roadrunner-server/sdk/v4/pool"
"os"
)
type Config struct {
Amqp *AmqpConfig `mapstructure:"amqp"`
Pool *pool.Config `mapstructure:"pool"`
Consumers []*ConsumerConfig `mapstructure:"consumers"`
}
type AmqpConfig struct {
Addr string `mapstructure:"addr"`
Queue []*QueueConfig `mapstructure:"queue"`
Exchange []*ExchangeConfig `mapstructure:"exchange"`
QueueBind []*QueueBindConfig `mapstructure:"queueBind"`
}
type QueueConfig struct {
Name string `mapstructure:"name"`
Durable bool `mapstructure:"durable"`
AutoDelete bool `mapstructure:"autoDelete"`
Exclusive bool `mapstructure:"exclusive"`
NoWait bool `mapstructure:"noWait"`
Args map[string]interface{} `mapstructure:"args"`
}
type ExchangeConfig struct {
Name string `mapstructure:"name"`
Kind string `mapstructure:"kind"`
Durable bool `mapstructure:"durable"`
AutoDelete bool `mapstructure:"autoDelete"`
Internal bool `mapstructure:"internal"`
NoWait bool `mapstructure:"noWait"`
Args map[string]interface{} `mapstructure:"args"`
}
type QueueBindConfig struct {
Queue string `mapstructure:"queue"`
Exchange string `mapstructure:"exchange"`
Key string `mapstructure:"key"`
NoWait bool `mapstructure:"noWait"`
Args map[string]interface{} `mapstructure:"args"`
}
type ConsumerConfig struct {
Queue string `mapstructure:"queue"`
Prefetch int `mapstructure:"prefetch"`
Durable bool `mapstructure:"durable"`
RequeueOnFail *bool `mapstructure:"requeue_on_fail"`
ConsumerID string `mapstructure:"consumer_id"`
Concurrency int `mapstructure:"concurrency"`
}
func (c *Config) InitDefaults() {
if c.Pool != nil {
c.Pool.InitDefaults()
}
for _, consumer := range c.Consumers {
consumer.InitDefaults()
}
}
func (c *ConsumerConfig) InitDefaults() {
if c.Prefetch == 0 {
c.Prefetch = 1
}
if c.RequeueOnFail == nil {
requeueOnFail := true
c.RequeueOnFail = &requeueOnFail
}
}
func (c *Config) ExpandEnv() {
for _, consumer := range c.Consumers {
consumer.ExpandEnv()
}
for _, queue := range c.Amqp.Queue {
queue.ExpandEnv()
}
for _, exchange := range c.Amqp.Exchange {
exchange.ExpandEnv()
}
for _, queueBind := range c.Amqp.QueueBind {
queueBind.ExpandEnv()
}
}
func (c *ConsumerConfig) ExpandEnv() {
c.Queue = config.ExpandVal(c.Queue, os.Getenv)
c.ConsumerID = config.ExpandVal(c.ConsumerID, os.Getenv)
}
func (c *QueueConfig) ExpandEnv() {
c.Name = config.ExpandVal(c.Name, os.Getenv)
for key, value := range c.Args {
if valueStr, ok := value.(string); ok {
c.Args[key] = config.ExpandVal(valueStr, os.Getenv)
}
}
}
func (c *ExchangeConfig) ExpandEnv() {
c.Name = config.ExpandVal(c.Name, os.Getenv)
c.Kind = config.ExpandVal(c.Kind, os.Getenv)
for key, value := range c.Args {
if valueStr, ok := value.(string); ok {
c.Args[key] = config.ExpandVal(valueStr, os.Getenv)
}
}
}
func (c *QueueBindConfig) ExpandEnv() {
c.Queue = config.ExpandVal(c.Queue, os.Getenv)
c.Exchange = config.ExpandVal(c.Exchange, os.Getenv)
c.Key = config.ExpandVal(c.Key, os.Getenv)
for key, value := range c.Args {
if valueStr, ok := value.(string); ok {
c.Args[key] = config.ExpandVal(valueStr, os.Getenv)
}
}
}