-
Notifications
You must be signed in to change notification settings - Fork 72
/
main.go
51 lines (45 loc) · 1.34 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
package main
import (
"example-apps/proxy/handlers"
"fmt"
"log"
"net/http"
"os"
"strconv"
)
func launchHandler(port int, downloadHandler, digHandler, pingHandler, proxyHandler, statsHandler, uploadHandler, echoSourceIPHandler http.Handler) {
mux := http.NewServeMux()
mux.Handle("/download/", downloadHandler)
mux.Handle("/dig/", digHandler)
mux.Handle("/ping/", pingHandler)
mux.Handle("/proxy/", proxyHandler)
mux.Handle("/stats", statsHandler)
mux.Handle("/upload", uploadHandler)
mux.Handle("/echosourceip", echoSourceIPHandler)
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{}
digHandler := &handlers.DigHandler{}
proxyHandler := &handlers.ProxyHandler{
Stats: stats,
}
statsHandler := &handlers.StatsHandler{
Stats: stats,
}
uploadHandler := &handlers.UploadHandler{}
echoSourceIPHandler := &handlers.EchoSourceIPHandler{}
launchHandler(systemPort, downloadHandler, digHandler, pingHandler, proxyHandler, statsHandler, uploadHandler, echoSourceIPHandler)
}