1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

http/health: add health checker (#830)

* add health checker
This commit is contained in:
Tony Chen
2021-04-15 16:48:31 +08:00
committed by GitHub
parent e93da2468c
commit e35fd9af6f
4 changed files with 106 additions and 139 deletions
+34
View File
@@ -0,0 +1,34 @@
package main
import (
"context"
"errors"
"log"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/transport/http"
"github.com/go-kratos/kratos/v2/transport/http/health"
)
func main() {
handler := health.NewHandler()
handler.AddChecker("mysql", func(ctx context.Context) error {
return nil
})
handler.AddObserver("redis", func(ctx context.Context) error {
return errors.New("connection refused")
})
httpSrv := http.NewServer(http.Address(":8000"))
httpSrv.Handle("/healthz", handler)
app := kratos.New(
kratos.Name("mux"),
kratos.Server(
httpSrv,
),
)
if err := app.Run(); err != nil {
log.Println(err)
}
}