-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (50 loc) · 1.11 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
/*
* amqp-quacker
*
*
* Contact: [email protected]
*/
package main
import (
"amqp-quacker/app"
"fmt"
"os"
"runtime"
)
func main() {
fmt.Printf("Server started\n")
amqpConfig := app.QuackerConfig{
Host: getEnv("QUACKER_HOST", "127.0.0.1"),
Port: getEnv("QUACKER_PORT", "5672"),
Username: getEnv("QUACKER_USERNAME", ""),
Password: getEnv("QUACKER_PASSWORD", ""),
Exchange: getEnv("QUACKER_EXCHANGE",""),
Topic: getEnvOrFail("QUACKER_TOPIC"),
Interval: getEnv("QUACKER_INTERVAL", "1000"),
DataFile: getEnv("QUACKER_DATAFILE", "/data.json"),
DryRun: getEnv("QUACKER_DRYRUN", "") != "",
}
quacker := app.NewQuacker(amqpConfig)
runtime.SetFinalizer(&quacker, func(obj *app.Quacker) {
obj.Close()
})
err := quacker.Start()
if(err != nil){
fmt.Println(err)
}
defer quacker.Close()
}
func getEnv(key string, defaultValue string) string {
value, found := os.LookupEnv(key)
if found == false {
return defaultValue
}
return value
}
func getEnvOrFail(key string) string {
value, found := os.LookupEnv(key)
if found == false {
panic("Need env key" + key)
}
return value
}