-
Notifications
You must be signed in to change notification settings - Fork 1
/
updater.go
55 lines (46 loc) · 1017 Bytes
/
updater.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
54
55
package beacon
import (
"crypto/tls"
"log"
"net/http"
"time"
"github.com/alexallah/ethereum-healthmon/internal/common"
)
func StartUpdater(state *common.State, addr string, timeout int64, certFile string) {
client := httpClient(certFile, timeout)
// add protocol
if certFile == "" {
addr = "http://" + addr
} else {
addr = "https://" + addr
}
go update(state, addr, client)
}
func update(state *common.State, addr string, client *http.Client) {
for {
time.Sleep(time.Second)
err := isReady(addr, client)
if err != nil {
state.Error(err)
} else {
state.SetHealthy()
}
}
}
func httpClient(certFile string, timeout int64) *http.Client {
var tlsConfig *tls.Config
if certFile != "" {
var err error
tlsConfig, err = getTLSConfig(certFile)
if err != nil {
log.Panic("can not get dialOption", err)
}
}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
return &http.Client{
Transport: transport,
Timeout: time.Duration(timeout) * time.Second,
}
}