-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
48 lines (42 loc) · 1.14 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
43
44
45
46
47
48
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/stakewise/ethnode-sidecar/clients"
"github.com/stakewise/ethnode-sidecar/config"
)
func main() {
cfg, err := config.NewConfig()
if err != nil {
log.Fatal(err)
}
router := mux.NewRouter()
router.Use(loggingMiddleware)
eth1 := clients.NewEth1Client()
eth2 := clients.NewEth2Client()
router.HandleFunc("/eth1/readiness", eth1.HealthCheck).Methods(http.MethodGet)
router.HandleFunc("/eth1/liveness", eth1.HealthCheck).Methods(http.MethodGet)
router.HandleFunc("/eth2/readiness", eth2.Readiness).Methods(http.MethodGet)
router.HandleFunc("/eth2/liveness", eth2.Liveness).Methods(http.MethodGet)
srv := &http.Server{
Handler: router,
Addr: cfg.Server.BindAddr,
WriteTimeout: 5 * time.Second,
ReadTimeout: 5 * time.Second,
}
fmt.Println("Starting server:", cfg.Server.BindAddr)
log.Fatal(srv.ListenAndServe())
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf(
"%s %s",
r.Method,
r.RequestURI,
)
next.ServeHTTP(w, r)
})
}