In Go, you can implement health and readiness endpoints as part of your web server to monitor the status of your application. These endpoints are commonly used in microservices environments and Kubernetes applications to ensure that your application is running smoothly and is ready to handle requests.
The health endpoint is used to check if the application is alive and functioning. A simple "/health" endpoint can return a 200 OK response.
The readiness endpoint checks if the application is ready to handle traffic. A "/readiness" endpoint might return a 200 OK response when the application is prepared to accept requests.
package main
import (
"fmt"
"net/http"
)
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "OK")
}
func readinessHandler(w http.ResponseWriter, r *http.Request) {
// You can add more checks here
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "Ready")
}
func main() {
http.HandleFunc("/health", healthHandler)
http.HandleFunc("/readiness", readinessHandler)
fmt.Println("Starting server on :8080")
http.ListenAndServe(":8080", nil)
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?