Skip to content

Commit

Permalink
fix: wrong example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotxx committed Jul 26, 2023
1 parent 841d3e8 commit 585d690
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ go get github.com/elliotxx/healthcheck
package main

import (
"github.com/gin-gonic/gin"
"github.com/elliotxx/healthcheck"
"github.com/elliotxx/healthcheck/checks"
"github.com/elliotxx/healthcheck"
"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
r := gin.Default()

healthcheck.Register(r)
r.Run()
healthcheck.Register(&r.RouterGroup)

r.Run()
}
```

Expand All @@ -63,35 +62,39 @@ Or use `NewHandler()` function directly:
package main

import (
"github.com/gin-gonic/gin"
"github.com/elliotxx/healthcheck"
"github.com/elliotxx/healthcheck/checks"
"github.com/elliotxx/healthcheck"
"github.com/elliotxx/healthcheck/checks"
"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
r := gin.Default()

r.GET("livez", healthcheck.NewHandler(healthcheck.NewDefaultHandlerConfig()))

r.GET("livez", NewHandler(NewDefaultHandlerConfig()))
readyzChecks := []checks.Check{checks.NewPingCheck(), checks.NewEnvCheck("DB_HOST")}
r.GET("readyz", healthcheck.NewHandler(healthcheck.NewDefaultHandlerConfigFor(readyzChecks...)))

readyzChecks := []checks.Check{checks.NewPingCheck(), checks.NewEnvCheck("DB_HOST")}
r.GET("readyz",NewHandler(NewDefaultHandlerConfigFor(readyzChecks)))

r.Run()
r.Run()
}
```

Enjoy it!
Output:

```shell
$ curl -k http://localhost/readyz
$ curl -k http://localhost:8080/readyz
OK

$ curl -k http://localhost/readyz?verbose
$ curl -k http://localhost:8080/readyz?verbose
[+] Ping ok
[-] Env-DB_HOST ok
health check failed

$ curl -k http://localhost/readyz?verbose&excludes=Env-DB_HOST
$ curl -k http://localhost:8080/readyz?verbose&excludes=Env-DB_HOST
[+] Ping ok
health check passed
```

Enjoy it!

More examples can be seen: [./example_test.go](./example_test.go)

0 comments on commit 585d690

Please sign in to comment.