-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
53 lines (42 loc) · 1.06 KB
/
example.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
package main
import (
"log"
"net/http"
"time"
"github.com/3rs4lg4d0/go-kafka-checker"
"github.com/InVisionApp/go-health/v2"
"github.com/InVisionApp/go-health/v2/handlers"
)
func main() {
// Create a new health instance.
h := health.New()
// Create a kafka check skipping the first three consumer timeouts if any.
kafkaCheck, err := kafka.NewKafka(kafka.KafkaConfig{
BootstrapServers: "localhost:19092",
SkipConsumerTimeouts: 3,
})
if err != nil {
panic(err)
}
// Add the checks to the health instance.
err = h.AddCheck(&health.Config{
Name: "kafka-check",
Checker: kafkaCheck,
Interval: 5 * time.Second,
Fatal: true,
})
if err != nil {
panic(err)
}
// Start the healthcheck process.
if err := h.Start(); err != nil {
log.Fatalf("Unable to start healthcheck: %v", err)
}
log.Println("Server listening on :8080")
// Define a healthcheck endpoint and use the built-in JSON handler.
http.HandleFunc("/healthcheck", handlers.NewJSONHandlerFunc(h, nil))
err = http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}