Skip to content

Commit

Permalink
example code in server.go updated
Browse files Browse the repository at this point in the history
  • Loading branch information
hojabri committed Apr 25, 2021
1 parent 1c998df commit 2347385
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions _examples/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ import (
)

func main() {
h, _ := health.New()
// custom health check example (fail)
health.Register(health.Config{
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)
health.Register(health.Config{
h.Register(health.Config{
Name: "some-custom-check-success",
Check: func(context.Context) error { return nil },
})

// http health check example
health.Register(health.Config{
h.Register(health.Config{
Name: "http-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand All @@ -38,7 +39,7 @@ func main() {
})

// postgres health check example
health.Register(health.Config{
h.Register(health.Config{
Name: "postgres-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand All @@ -48,7 +49,7 @@ func main() {
})

// mysql health check example
health.Register(health.Config{
h.Register(health.Config{
Name: "mysql-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand All @@ -61,7 +62,7 @@ func main() {
// 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".
health.Register(health.Config{
h.Register(health.Config{
Name: "rabbit-aliveness-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Expand All @@ -70,6 +71,6 @@ func main() {
}),
})

http.Handle("/status", health.Handler())
http.Handle("/status", h.Handler())
http.ListenAndServe(":3000", nil)
}

0 comments on commit 2347385

Please sign in to comment.