-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (50 loc) · 1.44 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
package main
import (
"ArcSpy-Server/arcapi"
"ArcSpy-Server/database"
mw "ArcSpy-Server/middleware"
"github.com/gookit/config/v2"
log "github.com/sirupsen/logrus"
"net/http"
)
func setupRoutes(serverMux *http.ServeMux) {
serverMux.HandleFunc("/player/sync", mw.ApplyMiddleware(playerSyncHandler,
mw.MethodMiddleware("POST"),
mw.RateLimitMiddleware(mw.RateLimitOptions{
RateLimit: 1,
BurstLimit: 1,
})))
serverMux.HandleFunc("/player/data", mw.ApplyMiddleware(playerDataHandler,
mw.MethodMiddleware("GET"),
mw.AuthMiddleware()))
serverMux.HandleFunc("/player/scores", mw.ApplyMiddleware(playerScoreHandler,
mw.MethodMiddleware("GET"),
mw.AuthMiddleware()))
serverMux.HandleFunc("/webapi/", mw.ApplyMiddleware(arcapi.WebAPIHandler,
mw.MethodMiddleware("GET"),
mw.AuthMiddleware()))
serverMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mw.RespondWithJSON(w, 404, "api not found", nil)
})
}
func main() {
initConfig()
database.Create()
serverPort := config.SubDataMap("server").Str("port")
serverMux := http.NewServeMux()
setupRoutes(serverMux)
server := &http.Server{
Addr: ":" + serverPort,
Handler: serverMux,
}
go func(server *http.Server) {
log.Info("Running ArcSpy Server on http://localhost:" + serverPort)
if err := server.ListenAndServe(); err != nil {
log.Panic(err)
}
}(server)
err := watchConfig()
if err != nil {
log.Panic("Failed to listen config file: ", err)
}
}