Skip to content

Commit

Permalink
Add required methods to HealthInfoV3 (#234)
Browse files Browse the repository at this point in the history
- String
- JSON
- GetError
- GetStatus
- GetTimestamp
  • Loading branch information
anjalshireesh authored Oct 12, 2023
1 parent 4bedcdb commit 59bc761
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions health-old.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,41 @@ type HealthInfoV2 struct {
Minio MinioHealthInfo `json:"minio,omitempty"`
}

func (info HealthInfoV2) String() string {
data, err := json.Marshal(info)
if err != nil {
panic(err) // This never happens.
}
return string(data)
}

// JSON returns this structure as JSON formatted string.
func (info HealthInfoV2) JSON() string {
data, err := json.MarshalIndent(info, " ", " ")
if err != nil {
panic(err) // This never happens.
}
return string(data)
}

// GetError - returns error from the cluster health info v2
func (info HealthInfoV2) GetError() string {
return info.Error
}

// GetStatus - returns status of the cluster health info v2
func (info HealthInfoV2) GetStatus() string {
if info.Error != "" {
return "error"
}
return "success"
}

// GetTimestamp - returns timestamp from the cluster health info v2
func (info HealthInfoV2) GetTimestamp() time.Time {
return info.TimeStamp
}

// HealthInfoV3 - MinIO cluster's health Info version 3
type HealthInfoV3 struct {
Version string `json:"version"`
Expand All @@ -61,7 +96,7 @@ type HealthInfoV3 struct {
Minio MinioHealthInfo `json:"minio,omitempty"`
}

func (info HealthInfoV2) String() string {
func (info HealthInfoV3) String() string {
data, err := json.Marshal(info)
if err != nil {
panic(err) // This never happens.
Expand All @@ -70,29 +105,29 @@ func (info HealthInfoV2) String() string {
}

// JSON returns this structure as JSON formatted string.
func (info HealthInfoV2) JSON() string {
func (info HealthInfoV3) JSON() string {
data, err := json.MarshalIndent(info, " ", " ")
if err != nil {
panic(err) // This never happens.
}
return string(data)
}

// GetError - returns error from the cluster health info v2
func (info HealthInfoV2) GetError() string {
// GetError - returns error from the cluster health info
func (info HealthInfoV3) GetError() string {
return info.Error
}

// GetStatus - returns status of the cluster health info v2
func (info HealthInfoV2) GetStatus() string {
// GetStatus - returns status of the cluster health info
func (info HealthInfoV3) GetStatus() string {
if info.Error != "" {
return "error"
}
return "success"
}

// GetTimestamp - returns timestamp from the cluster health info v2
func (info HealthInfoV2) GetTimestamp() time.Time {
// GetTimestamp - returns timestamp from the cluster health info
func (info HealthInfoV3) GetTimestamp() time.Time {
return info.TimeStamp
}

Expand Down

0 comments on commit 59bc761

Please sign in to comment.