-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
95 lines (75 loc) · 1.94 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"sync"
"github.com/eu-evops/edulink/pkg/cache"
"github.com/eu-evops/edulink/pkg/cache/common"
"github.com/eu-evops/edulink/pkg/edulink"
"github.com/eu-evops/edulink/pkg/web"
"github.com/eu-evops/edulink/pkg/worker"
)
var (
EdulinkUsername string
EdulinkPassword string
MailgunApiKey string
appCache *cache.Cache
)
func init() {
EdulinkUsername = os.Getenv("EDULINK_USERNAME")
EdulinkPassword = os.Getenv("EDULINK_PASSWORD")
MailgunApiKey = os.Getenv("MAILGUN_API_KEY")
if EdulinkUsername == "" || EdulinkPassword == "" {
fmt.Println("Please set EDULINK_USERNAME and EDULINK_PASSWORD environment variables")
os.Exit(1)
}
if MailgunApiKey == "" {
fmt.Println("Please set MAILGUN_API_KEY environment variable")
os.Exit(1)
}
appCache = cache.New(&common.CacheOptions{
CacheType: common.Redis,
RedisHost: os.Getenv("REDIS_HOST"),
RedisUsername: os.Getenv("REDIS_USERNAME"),
RedisPassword: os.Getenv("REDIS_PASSWORD"),
})
edulink.Cache = appCache
if err := appCache.Initialise(); err != nil {
panic(err)
}
}
func main() {
fmt.Printf("Welcome to EduLink scanner.\n")
webserverEnabled := flag.Bool("webserver", false, "Enable webserver")
webserverPort := flag.Int("port", 8080, "Port to listen on")
flag.Parse()
webServer := web.NewServer(*webserverPort)
if err := webServer.Start(); err != nil {
panic(err)
}
workerOptions := &worker.WorkerOptions{
EdulinkUsername: EdulinkUsername,
EdulinkPassword: EdulinkPassword,
Cache: appCache,
MailgunApiKey: MailgunApiKey,
}
worker := worker.NewWorker(workerOptions)
if err := worker.Start(); err != nil {
panic(err)
}
wg := sync.WaitGroup{}
if *webserverEnabled {
wg.Add(1)
fmt.Println("Webserver enabled, listening on port", *webserverPort)
s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt)
go func() {
<-s
wg.Done()
webServer.Stop()
}()
wg.Wait()
}
}