-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
47 lines (37 loc) · 901 Bytes
/
app.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
type Response struct {
Message string `json:"message"`
Host string `json:"host"`
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
hostname, _ := os.Hostname()
response := Response{
Message: "Default backend - 404",
Host: hostname,
}
json.NewEncoder(w).Encode(response)
}
func healthzHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
response := Response{
Message: "OK",
Host: "healthy",
}
json.NewEncoder(w).Encode(response)
}
func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/healthz", healthzHandler)
port := "8080"
fmt.Printf("Starting server on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}