-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (32 loc) · 1.1 KB
/
main.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
package main
import (
"fmt"
"net/http"
"time"
conf "github.com/kaschula/kafka-healthchecker/config"
"github.com/kaschula/kafka-healthchecker/healthcheck"
kafkaService "github.com/kaschula/kafka-healthchecker/kafka"
schedulerService "github.com/kaschula/kafka-healthchecker/scheduler"
)
func main() {
config := conf.AppConfigFromFlags()
fmt.Println("config", config)
scheduler := schedulerService.New(config)
kafkaCli := createKafkaCli(config)
state := healthcheck.NewRepository(healthcheck.New(false, time.Now(), "Initializing"))
// Setup server
http.HandleFunc("/check", func(res http.ResponseWriter, request *http.Request) {
response, err := state.GetState().ToJson()
if err != nil {
response = []byte(fmt.Sprintf("{\"error\":\"%v\"}", err.Error()))
}
res.Write(response)
})
fmt.Println("Starting scheduler....")
go scheduler.Run(kafkaService.CreateHandler(config, kafkaCli, &state))
fmt.Println("Starting Server....")
http.ListenAndServe(":"+config.HttpPort, nil)
}
func createKafkaCli(config conf.AppConfig) kafkaService.KafkaCli {
return kafkaService.NewSegmentionAdapaterDialer()
}