forked from recursecenter/pairing-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (57 loc) · 1.42 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
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"cloud.google.com/go/firestore"
)
// It's alive! The application starts here.
func main() {
// setting up database connection: 2 clients encapsulated into PairingLogic struct
ctx := context.Background()
rc, err := firestore.NewClient(ctx, "pairing-bot-284823")
if err != nil {
log.Panic(err)
}
defer rc.Close()
ac, err := firestore.NewClient(ctx, "pairing-bot-284823")
if err != nil {
log.Panic(err)
}
defer ac.Close()
rdb := &FirestoreRecurserDB{
client: rc,
}
adb := &FirestoreAPIAuthDB{
client: ac,
}
ur := &zulipUserRequest{}
un := &zulipUserNotification{
botUsername: "[email protected]",
zulipAPIURL: "https://recurse.zulipchat.com/api/v1/messages",
}
pl := &PairingLogic{
rdb: rdb,
adb: adb,
ur: ur,
un: un,
}
http.HandleFunc("/", http.NotFound) // will this handle anything that's not defined?
http.HandleFunc("/webhooks", pl.handle) // from zulip
http.HandleFunc("/match", pl.match) // from GCP
http.HandleFunc("/endofbatch", pl.endofbatch) // manually triggered
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
if m, ok := os.LookupEnv("PB_MAINT"); ok {
if m == "true" {
maintenanceMode = true
}
}
log.Printf("Listening on port %s", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}