Skip to content

Commit

Permalink
feat: inventory-service-mock-go add liveness and readiness probes
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarschulte committed Jan 15, 2025
1 parent efba2d2 commit 6db09f6
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions inventory-service-mock-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,29 @@ func isAvailable(w http.ResponseWriter, r *http.Request) {
}
}

func healthHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("OK"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func readinessHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("READY"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func main() {
http.HandleFunc("/inventory", isAvailable)
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("ok"))
if err != nil {
log.Error().Err(err).Msg("Failed to write response")
return
}
})
http.HandleFunc("/actuator/health/liveness", healthHandler) // Liveness Probe
http.HandleFunc("/actuator/health/readiness", readinessHandler) // Readiness Probe
port := "8084"
println("Server running on port:", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
Expand Down

0 comments on commit 6db09f6

Please sign in to comment.