2020-04-10 08:27:43 +02:00
|
|
|
package serv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
var healthyResponse = []byte("All's Well")
|
|
|
|
|
2020-05-24 16:44:00 +02:00
|
|
|
func health(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ct, cancel := context.WithTimeout(r.Context(), conf.DB.PingTimeout)
|
2020-04-10 08:27:43 +02:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := db.PingContext(ct); err != nil {
|
|
|
|
log.Printf("ERR error pinging database: %s", err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := w.Write(healthyResponse); err != nil {
|
|
|
|
log.Printf("ERR error writing healthy response: %s", err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|