Skip to content

Commit

Permalink
Made hypervisor ping endpoint a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
志宇 committed Mar 2, 2020
1 parent 36fa94c commit bdc72de
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit bdc72de

Please sign in to comment.