-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
64 lines (48 loc) · 1.63 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
package main
import (
"log"
"net/http"
"os"
// "github.com/go-playground/webhooks/v6"
"github.com/anirudhRowjee/bunsamosa-bot/globals"
"github.com/anirudhRowjee/bunsamosa-bot/handlers"
"github.com/rs/cors"
)
// TODO Write YAML Parsing for environment variables
func main() {
// parse YAML File to read in secrets
// Initialize state
// TODO Separate the YAML Loading from the value setting
// var YAML_SECRETS_PATH string
YAML_SECRETS_PATH := ""
// Check if we're in a development environment
IS_DEV_ENV := os.Getenv("BUNSAMOSA_DEV_MODE")
if IS_DEV_ENV == "1" {
YAML_SECRETS_PATH = "./secrets-dev.yaml"
} else {
YAML_SECRETS_PATH = "/root/bunsamosa-bot/secrets.yaml"
}
globals.Myapp = globals.App{}
globals.Myapp.Parse_from_YAML(YAML_SECRETS_PATH)
log.Println("[INIT] YAML Parsed successfully")
// Initialize the Github Client
globals.Myapp.Initialize_github_client()
// Initialize the database
globals.Myapp.Initialize_database()
// Serve!
// TODO use Higher-Order Functions to generate this response function
// with the webhook secret from the YAML Parsed into the app in scope
mux := http.NewServeMux()
mux.HandleFunc("/Github", handlers.WebhookHandler)
mux.HandleFunc("/ping", handlers.PingHandler)
mux.HandleFunc("/lb_all", handlers.Leaderboard_allrecords)
mux.HandleFunc("/leaderboard", handlers.Leaderboard_materialized)
log.Println("[INIT] Registered all routes")
handler := cors.Default().Handler(mux)
log.Println("[INIT] Initialized CORS")
log.Println("[INIT] Starting Web Server")
err := http.ListenAndServe("0.0.0.0:3000", handler)
if err != nil && err != http.ErrServerClosed {
log.Fatal(err)
}
}