mirror of
https://github.com/go-kratos/kratos.git
synced 2026-05-22 10:15:24 +02:00
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user