-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (45 loc) · 1.32 KB
/
main.go
File metadata and controls
49 lines (45 loc) · 1.32 KB
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 main
import (
"context"
"github.com/InVisionApp/go-health/checkers"
"github.com/alexliesenfeld/health"
"log"
"net/http"
"net/url"
"time"
)
func main() {
// Create checkers as usual.
googleURL, err := url.Parse("https://www.google.com")
if err != nil {
log.Fatalln(err)
}
check, err := checkers.NewHTTP(&checkers.HTTPConfig{
URL: googleURL,
Timeout: 3 * time.Second,
})
if err != nil {
log.Fatalln(err)
}
// Add the check in the Checker configuration
http.Handle("/health", health.NewHandler(
health.NewChecker(
health.WithCheck(health.Check{
Name: "google",
Check: func(_ context.Context) error {
_, err := check.Status()
return err
},
// InVisionApp/go-health does not support context based timeouts.
// This timeout of 5 seconds will not propagate to the check function,
// because check.Status (see above) does not accept a context.
// Timeouts need to be set before the check is used (see usage
// of checkers.NewHTTP above, where we set a timeout of 3 seconds).
// Since this value here is set to a high number by default
// (currently 10 seconds), you can basically leave it away here and only
// define the timeout in the checkers.HTTPConfig above.
Timeout: 5 * time.Second,
}),
)))
log.Fatalln(http.ListenAndServe(":3000", nil))
}