-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (40 loc) · 919 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
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"log"
"net/http"
"time"
)
const (
tree = "Sequoia"
)
type resp struct {
MyFavouriteTree string `json:"myFavouriteTree"`
}
func main() {
staticResponse := resp{tree}
http.HandleFunc(
"/tree",
func(w http.ResponseWriter, r *http.Request) {
log.Printf("\"%s\" request with header \"%s\" to \"%s\"", r.Method, r.Header, r.URL)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(staticResponse)
},
)
// The /healthz endpoint is added so that kubernetes can evalueate if the pod
// needs restarting
http.HandleFunc(
"/healthz",
func(w http.ResponseWriter, r *http.Request) {
log.Println("healthz ping")
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
},
)
srv := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
Addr: ":8090",
}
log.Fatal(srv.ListenAndServe())
}