From bdc72deb9d13a97f6475e192aee8e3f859d19cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Mon, 2 Mar 2020 20:18:17 +0800 Subject: [PATCH] Made hypervisor ping endpoint a separate function. --- pkg/hypervisor/hypervisor.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index 1fb79d8e1..77cbb05ee 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -138,9 +138,7 @@ func (m *Hypervisor) ServeHTTP(w http.ResponseWriter, req *http.Request) { r.Route("/api", func(r chi.Router) { r.Use(middleware.Timeout(httpTimeout)) - r.Get("/ping", func(w http.ResponseWriter, r *http.Request) { - _, _ = w.Write([]byte(`"PONG!"`)) //nolint:errcheck - }) + r.Get("/ping", m.getPong()) if m.c.EnableAuth { r.Group(func(r chi.Router) { @@ -189,6 +187,14 @@ func (m *Hypervisor) ServeHTTP(w http.ResponseWriter, req *http.Request) { r.ServeHTTP(w, req) } +func (m *Hypervisor) getPong() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if _, err := w.Write([]byte(`"PONG!"`)); err != nil { + log.WithError(err).Warn("getPing: Failed to send PONG!") + } + } +} + // VisorHealth represents a visor's health report attached to hypervisor to visor request status type VisorHealth struct { Status int `json:"status"`