fix(health): explicitly ignore json.Encode errors in HTTP handler responses

This commit is contained in:
程智超0668000959 2026-06-26 22:57:48 +08:00
parent 1260fd8e2f
commit 0eb721fff7

View file

@ -162,7 +162,7 @@ func (s *Server) reloadHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "reload triggered"}) _ = json.NewEncoder(w).Encode(map[string]string{"status": "reload triggered"})
} }
func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) {
@ -176,7 +176,7 @@ func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) {
PID: os.Getpid(), PID: os.Getpid(),
} }
json.NewEncoder(w).Encode(resp) _ = json.NewEncoder(w).Encode(resp)
} }
func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) {
@ -190,7 +190,7 @@ func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) {
if !ready { if !ready {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(StatusResponse{ _ = json.NewEncoder(w).Encode(StatusResponse{
Status: "not ready", Status: "not ready",
Checks: checks, Checks: checks,
}) })
@ -200,7 +200,7 @@ func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) {
for _, check := range checks { for _, check := range checks {
if check.Status == "fail" { if check.Status == "fail" {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(StatusResponse{ _ = json.NewEncoder(w).Encode(StatusResponse{
Status: "not ready", Status: "not ready",
Checks: checks, Checks: checks,
}) })
@ -210,7 +210,7 @@ func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
uptime := time.Since(s.startTime) uptime := time.Since(s.startTime)
json.NewEncoder(w).Encode(StatusResponse{ _ = json.NewEncoder(w).Encode(StatusResponse{
Status: "ready", Status: "ready",
Uptime: uptime.String(), Uptime: uptime.String(),
Checks: checks, Checks: checks,