-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhealthchecks.go
49 lines (38 loc) · 945 Bytes
/
healthchecks.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
42
43
44
45
46
47
48
49
package healthchecks
import (
"fmt"
"github.com/google/uuid"
)
const (
// DefaultAPI base url for checks
DefaultAPI = "https://hc-ping.com"
// DefaultUserAgent for the client
DefaultUserAgent = "Go-Healthchecks (lib; +https://gitlab.com/etke.cc/go/healthchecks)"
)
// ErrLog used to log errors occurred during an operation
type ErrLog func(operation string, err error)
// global client
var global *Client
// DefaultErrLog if you don't provide one yourself
var DefaultErrLog = func(operation string, err error) {
fmt.Printf("healtchecks operation %q failed: %v\n", operation, err)
}
// New healthchecks client
func New(options ...Option) *Client {
rid, _ := uuid.NewRandom() //nolint:errcheck // ignore error
c := &Client{
rid: rid.String(),
}
c.init(options...)
if global == nil {
global = c
}
return c
}
// Global healthchecks client
func Global() *Client {
if global == nil {
global = New()
}
return global
}