-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
background-api: Add Healthchecks.io ping
- Loading branch information
1 parent
44eee35
commit 36e320d
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Package healthchecksio is a wrapper for API calls to HealthChecks.io | ||
package healthchecksio | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/carlmjohnson/errorx" | ||
"github.com/carlmjohnson/requests" | ||
) | ||
|
||
// Client is a convenient way to ping HealthChecks.io | ||
type Client struct { | ||
rb *requests.Builder | ||
} | ||
|
||
// New returns a configured client. If c is nil, http.DefaultClient is used. | ||
func New(uuid string, c *http.Client) Client { | ||
return Client{ | ||
requests. | ||
URL("https://hc-ping.com"). | ||
Path(uuid). | ||
Client(c), | ||
} | ||
} | ||
|
||
// Start calls the start HealthChecks.io endpoint | ||
func (cl Client) Start(ctx context.Context) (err error) { | ||
defer errorx.Trace(&err) | ||
|
||
return cl.rb.Clone(). | ||
Path("start"). | ||
Fetch(ctx) | ||
} | ||
|
||
// Status calls the HealthChecks.io status endpoint | ||
func (cl Client) Status(ctx context.Context, code int, msg []byte) (err error) { | ||
defer errorx.Trace(&err) | ||
|
||
return cl.rb.Clone(). | ||
Pathf("%d", code). | ||
BodyBytes(msg). | ||
Fetch(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters