Maint: healthcheck package interface rework

- return concrete struct type
- Add compilation checks for implementations
This commit is contained in:
Quentin McGaw (desktop)
2021-07-23 19:22:41 +00:00
parent c39ff5c233
commit 54610866f2
6 changed files with 64 additions and 54 deletions

View File

@@ -12,26 +12,28 @@ var (
ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK")
)
var _ Checker = (*Client)(nil)
type Checker interface {
Check(ctx context.Context, url string) error
}
type checker struct {
type Client struct {
httpClient *http.Client
}
func NewChecker(httpClient *http.Client) Checker {
return &checker{
func NewClient(httpClient *http.Client) *Client {
return &Client{
httpClient: httpClient,
}
}
func (h *checker) Check(ctx context.Context, url string) error {
func (c *Client) Check(ctx context.Context, url string) error {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return err
}
response, err := h.httpClient.Do(request)
response, err := c.httpClient.Do(request)
if err != nil {
return err
}