1package api 2 3import "context" 4 5func (c *Sys) Health() (*HealthResponse, error) { 6 r := c.c.NewRequest("GET", "/v1/sys/health") 7 // If the code is 400 or above it will automatically turn into an error, 8 // but the sys/health API defaults to returning 5xx when not sealed or 9 // inited, so we force this code to be something else so we parse correctly 10 r.Params.Add("uninitcode", "299") 11 r.Params.Add("sealedcode", "299") 12 r.Params.Add("standbycode", "299") 13 r.Params.Add("drsecondarycode", "299") 14 r.Params.Add("performancestandbycode", "299") 15 16 ctx, cancelFunc := context.WithCancel(context.Background()) 17 defer cancelFunc() 18 resp, err := c.c.RawRequestWithContext(ctx, r) 19 if err != nil { 20 return nil, err 21 } 22 defer resp.Body.Close() 23 24 var result HealthResponse 25 err = resp.DecodeJSON(&result) 26 return &result, err 27} 28 29type HealthResponse struct { 30 Initialized bool `json:"initialized"` 31 Sealed bool `json:"sealed"` 32 Standby bool `json:"standby"` 33 PerformanceStandby bool `json:"performance_standby"` 34 ReplicationPerformanceMode string `json:"replication_performance_mode"` 35 ReplicationDRMode string `json:"replication_dr_mode"` 36 ServerTimeUTC int64 `json:"server_time_utc"` 37 Version string `json:"version"` 38 ClusterName string `json:"cluster_name,omitempty"` 39 ClusterID string `json:"cluster_id,omitempty"` 40 LastWAL uint64 `json:"last_wal,omitempty"` 41} 42