-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathserver.go
76 lines (67 loc) · 2.13 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"errors"
"net/http"
"time"
"github.com/hellofresh/health-go/v5"
healthHttp "github.com/hellofresh/health-go/v5/checks/http"
healthMySql "github.com/hellofresh/health-go/v5/checks/mysql"
healthPg "github.com/hellofresh/health-go/v5/checks/postgres"
)
func main() {
h, _ := health.New(health.WithSystemInfo())
// custom health check example (fail)
h.Register(health.Config{
Name: "some-custom-check-fail",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: func(context.Context) error { return errors.New("failed during custom health check") },
})
// custom health check example (success)
h.Register(health.Config{
Name: "some-custom-check-success",
Check: func(context.Context) error { return nil },
})
// http health check example
h.Register(health.Config{
Name: "http-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthHttp.New(healthHttp.Config{
URL: `http://example.com`,
}),
})
// postgres health check example
h.Register(health.Config{
Name: "postgres-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthPg.New(healthPg.Config{
DSN: `postgres://test:[email protected]:32783/test?sslmode=disable`,
}),
})
// mysql health check example
h.Register(health.Config{
Name: "mysql-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthMySql.New(healthMySql.Config{
DSN: `test:test@tcp(0.0.0.0:32778)/test?charset=utf8`,
}),
})
// rabbitmq aliveness test example.
// Use it if your app has access to RabbitMQ management API.
// This endpoint declares a test queue, then publishes and consumes a message. Intended for use by monitoring tools. If everything is working correctly, will return HTTP status 200.
// As the default virtual host is called "/", this will need to be encoded as "%2f".
h.Register(health.Config{
Name: "rabbit-aliveness-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthHttp.New(healthHttp.Config{
URL: `http://guest:[email protected]:32780/api/aliveness-test/%2f`,
}),
})
http.Handle("/status", h.Handler())
http.ListenAndServe(":3000", nil)
}