-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (31 loc) · 1009 Bytes
/
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
package main
import (
"net/http"
"os"
"strconv"
)
func main() {
rankErr := initRankings()
if rankErr != nil {
logger.Error("unable to load rankings", "error", rankErr)
return
}
var listenPort, portErr = strconv.Atoi(os.Getenv("PORT"))
if portErr != nil {
listenPort = 4000
}
var listenAddress = os.Getenv("ADDRESS")
http.HandleFunc("/status.json", statusHandler)
http.HandleFunc("/{$}", staticHandler.ServeHTTP)
http.HandleFunc("/robots.txt", staticHandler.ServeHTTP)
http.HandleFunc("/favicon.ico", staticHandler.ServeHTTP)
http.HandleFunc("/favicon.svg", staticHandler.ServeHTTP)
http.HandleFunc("/images/", staticHandler.ServeHTTP)
http.HandleFunc("/api/rank.json", apiHandler)
http.HandleFunc("/api/multiple.json", multiHandler)
http.HandleFunc("/api/random.json", randomHandler)
err := http.ListenAndServe(listenAddress+":"+strconv.Itoa(listenPort), nil)
if err != nil {
logger.Error("unable to listen", "address", listenAddress, "port", listenPort, "error", err)
}
}