Files
RenewCMS/internal/infrastructure/update/httpHealthChecker.go
T

33 lines
648 B
Go

package update
import (
domain "RenewCMS/internal/domain/update"
"net/http"
"time"
)
const healthCheckTimeout = 2 * time.Second
type HTTPHealthChecker struct {
url string
client *http.Client
}
var _ domain.HealthChecker = &HTTPHealthChecker{}
func NewHTTPHealthChecker(port string) *HTTPHealthChecker {
return &HTTPHealthChecker{
url: "http://127.0.0.1:" + port + "/healthz",
client: &http.Client{Timeout: healthCheckTimeout},
}
}
func (c *HTTPHealthChecker) Healthy() bool {
response, err := c.client.Get(c.url)
if err != nil {
return false
}
defer response.Body.Close()
return response.StatusCode == http.StatusOK
}