-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
41 lines (37 loc) · 1.03 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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
func main() {
addr := ":" + os.Getenv("PORT")
fmt.Println("Listening on", addr)
http.HandleFunc("/", staticHandler)
http.HandleFunc("/db", dbHandler)
http.HandleFunc("/opensearch-test", opensearchHandler)
http.HandleFunc("/influxdb-test", influxdbHandler)
http.HandleFunc("/redis-test", redisHandler)
http.HandleFunc("/s3-test", s3Handler)
http.HandleFunc("/sqs-test", sqsHandler)
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Fatal(err)
}
}
func staticHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=0,no-store,no-cache")
http.ServeFile(w, r, "static/"+r.URL.Path[1:])
}
func writeJson(w http.ResponseWriter, data interface{}) {
output, err := json.MarshalIndent(data, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Cache-Control", "max-age=0,no-store,no-cache")
w.Header().Set("Content-Type", "application/json")
w.Write(output)
}