forked from stellar/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_horizon_up.go
52 lines (42 loc) · 870 Bytes
/
test_horizon_up.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
package main
import (
"encoding/json"
"log"
"net/http"
"os"
"time"
)
const timeout = 3 * time.Minute
type Root struct {
CoreSupportedProtocolVersion int32 `json:"core_supported_protocol_version"`
}
func main() {
startTime := time.Now()
for {
time.Sleep(5 * time.Second)
logLine("Waiting for Horizon to start")
if time.Since(startTime) > timeout {
logLine("Timeout")
os.Exit(-1)
}
resp, err := http.Get("http://localhost:8000")
if err != nil {
logLine(err)
continue
}
var root Root
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&root)
if err != nil {
logLine(err)
continue
}
if root.CoreSupportedProtocolVersion > 0 {
logLine("Horizon has started and is communicating with stellar-core!")
os.Exit(0)
}
}
}
func logLine(text interface{}) {
log.Println("\033[32;1m[test]\033[0m", text)
}