Mode:
Duration:
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
package main
import (
"fmt"
"net/http"
)
var started = true
var healthy = true
func readinessProbe(w http.ResponseWriter, r *http.Request) {
if healthy {
fmt.Fprintln(w, "READY")
return
}
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, "NOT READY")
}
func livenessProbe(w http.ResponseWriter, r *http.Request) {
if healthy {
fmt.Fprintln(w, "ALIVE")
return
}
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "FAILED")
}
func startupProbe(w http.ResponseWriter, r *http.Request) {
if started {
fmt.Fprintln(w, "STARTED")
return
}
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, "STARTING")
}
func main() {
http.HandleFunc("/health/readiness", readinessProbe)
http.HandleFunc("/health/liveness", livenessProbe)
http.HandleFunc("/health/startup", startupProbe)
fmt.Println("Health check server running on :8080")
http.ListenAndServe(":8080", nil)
}Coding works best on desktop or with an external keyboard.