/
config.go
60 lines (52 loc) · 1.36 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
package gorabbit
import (
"github.com/dimonrus/porterr"
)
// Queue configuration
type RabbitQueue struct {
Server string
Exchange string
Internal bool
Type string
Name string
Passive bool
Durable bool
Exclusive bool
Nowait bool
AutoDelete bool `yaml:"autoDelete"`
RoutingKey []string `yaml:"routingKey"`
Arguments map[string]interface{}
}
// Registry consumer registry
type Registry map[string]*Consumer
// Servers server registry
type Servers map[string]RabbitServer
// Queues queue registry
type Queues map[string]RabbitQueue
// Config Rabbit config
type Config struct {
// Servers configuration
Servers Servers
// Queues configuration
Queues Queues
}
// GetServer Get server
func (c *Config) GetServer(name string) (*RabbitServer, porterr.IError) {
server, ok := c.Servers[name]
if !ok {
return nil, porterr.NewF(porterr.PortErrorSystem, "server %s not found in rabbit config", name)
}
if server.Vhost == "" {
return nil, porterr.NewF(porterr.PortErrorSystem, "vhost is incorrect for server %s in rabbit config", name)
}
return &server, nil
}
// GetQueue Get queue
func (c *Config) GetQueue(name string) (*RabbitQueue, porterr.IError) {
queue, ok := c.Queues[name]
if !ok {
return nil, porterr.NewF(porterr.PortErrorSystem, "queue %s not found in rabbit config", name)
}
queue.Name = name
return &queue, nil
}