/
health.go
50 lines (39 loc) · 977 Bytes
/
health.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
package atomicasset
import (
"github.com/eosswedenorg-go/unixtime"
)
// Types
type ChainHealth struct {
Status string `json:"status"`
HeadBlock int64 `json:"head_block"`
HeadTime unixtime.Time `json:"head_time"`
}
type RedisHealth struct {
Status string `json:"status"`
}
type PostgresHealth struct {
Status string `json:"status"`
Readers []map[string]interface{} `json:"readers"`
}
type HealthData struct {
Version string `json:"version"`
Postgres PostgresHealth `json:"postgres"`
Redis RedisHealth `json:"redis"`
Chain ChainHealth `json:"chain"`
}
// Responses
type Health struct {
APIResponse
Data HealthData
}
// Client API Functions
// GetHealth fetches "/health" from API
func (c *Client) GetHealth() (Health, error) {
var health Health
r, err := c.fetch("GET", "/health", nil, &health.APIResponse)
if err == nil {
// Parse json
err = r.Unmarshal(&health)
}
return health, err
}