-
Notifications
You must be signed in to change notification settings - Fork 6
/
healthcheck.go
41 lines (34 loc) · 1.23 KB
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package slimhttp
import (
"net/http"
"github.com/sirupsen/logrus"
)
// HealthcheckService defines all functionality for a healthcheckService
type HealthcheckService interface {
Healthcheck(r *http.Request) (interface{}, error)
}
// healthcheckService contains all dependencies for a HealthcheckService
type healthcheckService struct {
log *logrus.Entry
hostname string
}
// NewHealthcheckService generates a new Healthchecker service
func NewHealthcheckService(log *logrus.Logger, hostname string) HealthcheckService {
return &healthcheckService{
log: log.WithField("service", "healthcheck"),
hostname: hostname,
}
}
// HealthcheckResponse is the response to a healthcheck request
type HealthcheckResponse struct {
Status string `json:"status" xml:"status"`
Hostname string `json:"hostname" xml:"hostname"`
}
// Healthcheck handles and returns a healthcheck request, returning
// a 200 as well as a fully populated HealthcheckResponse
func (s *healthcheckService) Healthcheck(r *http.Request) (interface{}, error) {
l := s.log.WithField("handler", "Healthcheck")
l.Debug("New Healthcheck request received")
l.Debug("Returning newly generated Healthcheck")
return &HealthcheckResponse{Status: "OK", Hostname: s.hostname}, nil
}