-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
81 lines (68 loc) · 6.64 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
package main
import (
"net/http"
"os"
"github.com/gempir/gempbot/internal/auth"
"github.com/gempir/gempbot/internal/channelpoint"
"github.com/gempir/gempbot/internal/config"
"github.com/gempir/gempbot/internal/emotechief"
"github.com/gempir/gempbot/internal/emoteservice"
"github.com/gempir/gempbot/internal/eventsubmanager"
"github.com/gempir/gempbot/internal/helixclient"
"github.com/gempir/gempbot/internal/log"
"github.com/gempir/gempbot/internal/server"
"github.com/gempir/gempbot/internal/store"
"github.com/gempir/gempbot/internal/user"
"github.com/gempir/gempbot/internal/ws"
"github.com/rs/cors"
)
func main() {
cfg := config.FromEnv()
log.SetLogLevel(cfg.LogLevel)
db := store.NewDatabase(cfg)
argsWithoutProg := os.Args[1:]
if len(argsWithoutProg) == 1 && argsWithoutProg[0] == "migrate" {
db.Migrate()
os.Exit(0)
return
}
helixClient := helixclient.NewClient(cfg, db)
userAdmin := user.NewUserAdmin(cfg, db, helixClient)
authClient := auth.NewAuth(cfg, db, helixClient)
seventvClient := emoteservice.NewSevenTvClient(db)
emoteChief := emotechief.NewEmoteChief(cfg, db, helixClient, seventvClient)
channelPointManager := channelpoint.NewChannelPointManager(cfg, helixClient, db)
wsHandler := ws.NewWsHandler(authClient)
eventsubManager := eventsubmanager.NewEventsubManager(cfg, helixClient, db, emoteChief)
apiHandlers := server.NewApi(cfg, db, helixClient, userAdmin, authClient, emoteChief, eventsubManager, channelPointManager, seventvClient, wsHandler)
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf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KifhlnDXO9gsTm0X05dPsbDoxPgRyT/IgGvfzH+DMF0mtoGY/BHakUzOVsgluNbVUUPplPtxzNQ/Yrral404M0g+QLu5XmU+ULuMAZ2G3rgk3Yvhtnzo3iQBgrCUmEjUUKEUweatHRXb+0nYWEF8FNJzAxUj7UPPxQwqsKj1GWw4RXn138A7yzbmOjTsj4coEWgtU+ctzl/AZJUoV1nuHZ8F63gfIjNZpPoIhdGVDOXJUPXhEMXkvyLpSUyFmSEKbe20g4N1a78GAy5kWo25ZNJUC/C3QMNhVL5qYGgqZYE70FFxxA2Fqg8lYAf0aWWcLg9N2AEJNv/hDwQM9APYu4KAGD9jzVvl7U2oeWAUmxqpeCbh3zLvrspN3QEKMk/PoEmvpQVhoR6qXFgf+h9OqnEnPOegYCeR6x0H8zi4cnOdQmqgRyHknn9Yyytj52hyxcqYACIfutFcK3khwjtfmDdMr9TIu4RkS/x3fGv2rNQ5T4XUg4M9NKZ5EURWAic222yrYg1nQK1nzTZjGDyXGmT8YlkKtdsnYzLssVP4huhLhaK77xcVP0BNYMeJHr4TcWgwFzOIDXZ3FpzG/FiTeKXcBo63uEwENAH47qQouDnaIAjiB+Jg2QE1gf4GuPebn+WiJirfb4Ci30T3p9zrMnffxsAG+eiTiCGU6xS2A/mocAAAA==\" />"))
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "404 page not found", http.StatusNotFound)
})
mux.HandleFunc("/api/blocks", apiHandlers.BlocksHandler)
mux.HandleFunc("/api/fossabot", apiHandlers.FossabotHandler)
mux.HandleFunc("/api/callback", apiHandlers.CallbackHandler)
mux.HandleFunc("/api/emotehistory", apiHandlers.EmoteHistoryHandler)
mux.HandleFunc("/api/eventsub", apiHandlers.EventSubHandler)
mux.HandleFunc("/api/reward", apiHandlers.RewardHandler)
mux.HandleFunc("/api/subscriptions", apiHandlers.SubscriptionsHandler)
mux.HandleFunc("/api/userconfig", apiHandlers.UserConfigHandler)
mux.HandleFunc("/api/asset", apiHandlers.AssetCreationHandler)
mux.HandleFunc("/api/overlay", apiHandlers.OverlayHandler)
handler := cors.New(cors.Options{
AllowedOrigins: []string{cfg.WebBaseUrl},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
AllowedHeaders: []string{"*"},
AllowCredentials: true,
}).Handler(mux)
log.Info("Starting server on " + cfg.ListenAddress)
err := http.ListenAndServe(cfg.ListenAddress, handler)
if err != nil {
log.Fatal(err)
}
}