2019-12-09 07:59:30 +01:00
|
|
|
package serv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
var healthyResponse = []byte("All's Well")
|
|
|
|
|
|
|
|
func health(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
conn, err := db.Acquire(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
errlog.Error().Err(err).Msg("error acquiring connection from pool")
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-25 07:24:30 +01:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), conf.DB.PingTimeout)
|
|
|
|
defer cancel()
|
|
|
|
|
2019-12-09 07:59:30 +01:00
|
|
|
if err := conn.Conn().Ping(ctx); err != nil {
|
|
|
|
errlog.Error().Err(err).Msg("error pinging database")
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := w.Write(healthyResponse); err != nil {
|
|
|
|
errlog.Error().Err(err).Msg("error writing healthy response")
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|