-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.go
46 lines (41 loc) · 1.11 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
package main
import (
"example-apps/proxy/handlers"
"fmt"
"log"
"net/http"
"os"
"strconv"
)
func launchHandler(port int, downloadHandler, pingHandler, proxyHandler, statsHandler, uploadHandler http.Handler) {
mux := http.NewServeMux()
mux.Handle("/download/", downloadHandler)
mux.Handle("/ping/", pingHandler)
mux.Handle("/proxy/", proxyHandler)
mux.Handle("/stats", statsHandler)
mux.Handle("/upload", uploadHandler)
mux.Handle("/", &handlers.InfoHandler{
Port: port,
})
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), mux)
}
func main() {
systemPortString := os.Getenv("PORT")
systemPort, err := strconv.Atoi(systemPortString)
if err != nil {
log.Fatal("invalid required env var PORT")
}
stats := &handlers.Stats{
Latency: []float64{},
}
downloadHandler := &handlers.DownloadHandler{}
pingHandler := &handlers.PingHandler{}
proxyHandler := &handlers.ProxyHandler{
Stats: stats,
}
statsHandler := &handlers.StatsHandler{
Stats: stats,
}
uploadHandler := &handlers.UploadHandler{}
launchHandler(systemPort, downloadHandler, pingHandler, proxyHandler, statsHandler, uploadHandler)
}