Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: sort response of hastate before display #29

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/get/get_hastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func PrintGetHAStateResult(resp *http.Response, o api.RESTOptions) {
return
}

HAStateresp.Sort()

// Table Init
table := TableInit()
table.SetHeader(HASTATE_TITLE)
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/hastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package api

import (
"sort"
)

type HAState struct {
CommonAPI
}
Expand All @@ -40,3 +44,9 @@ type HAStateInfo struct {
// Instance Virtual IP address
Vip string `json:"vip,omitempty"`
}

func (haState HAStateGet) Sort() {
sort.Slice(haState.HAStateAttr, func(i, j int) bool {
return haState.HAStateAttr[i].Instance < haState.HAStateAttr[j].Instance
})
}