-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (71 loc) · 1.77 KB
/
main.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
package main
import (
"io"
"log"
"os"
"strings"
"time"
"github.com/dlpco/devops-tools/rabbitmq/compare"
"github.com/dlpco/devops-tools/rabbitmq/consumer"
"github.com/dlpco/devops-tools/rabbitmq/diff"
"github.com/dlpco/devops-tools/rabbitmq/loader"
"github.com/dlpco/devops-tools/rabbitmq/publish"
"github.com/dlpco/devops-tools/rabbitmq/transfer"
"github.com/urfave/cli"
)
func main() {
logFilename := "rabbitmq-" + time.Now().Format("20060102150405") + ".log"
f, err := os.OpenFile(logFilename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
log.SetOutput(io.MultiWriter(os.Stdout, f))
var config loader.Config
cfg := config.GetConfig()
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "consumer, c",
Usage: "Consumer message from queue",
},
cli.StringFlag{
Name: "producer, p",
Usage: "Produce message in queue",
},
cli.BoolFlag{
Name: "transfer, t",
Usage: "Transfer data between rabbitmq servers",
},
cli.BoolFlag{
Name: "compare, cp",
Usage: "Compare queues between rabbitmq servers",
},
cli.BoolFlag{
Name: "diff, df",
Usage: "Check users/vhosts/exchanges and queues between rabbitmq brokers",
},
}
app.Action = func(c *cli.Context) {
if c.Bool("consumer") {
consumer.Run(cfg.Server.AmqpUrl, cfg.Server.QueueName, cfg.Server.Vhost)
}
if c.String("producer") != "" {
if len(os.Args) < 2 {
log.Fatalln("You must specify message to write in queue")
}
msg := strings.Join(os.Args[2:], " ")
publish.Run(cfg.Server.AmqpUrl, cfg.Server.QueueName, cfg.Server.Vhost, []byte(msg))
}
if c.Bool("transfer") {
transfer.Run()
}
if c.Bool("compare") {
compare.Run()
}
if c.Bool("diff") {
diff.Run()
}
}
app.Run(os.Args)
}