diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-01-26 17:28:12 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-01-26 17:28:12 +0100 |
commit | 5ce05ccae810f532e73350a205b979faf2603235 (patch) | |
tree | 6a091bf3fad48f146d152f0336664dee8982a07c /utils.go | |
parent | c3c015d68a6f27bdb86c594ffbb481ee68f9e0c1 (diff) |
Sort projects and sdks list.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'utils.go')
-rw-r--r-- | utils.go | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -21,6 +21,7 @@ package main import ( "encoding/json" "fmt" + "sort" "strconv" "strings" @@ -90,6 +91,13 @@ func XdsServerComputeURL(endURL string) string { return "servers/" + strconv.Itoa(XdsServerIndexGet()) + endURL } +// Sort projects by Label +type _PrjByLabel []xaapiv1.ProjectConfig + +func (s _PrjByLabel) Len() int { return len(s) } +func (s _PrjByLabel) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s _PrjByLabel) Less(i, j int) bool { return s[i].Label < s[j].Label } + // ProjectsListGet Get the list of existing projects func ProjectsListGet(prjs *[]xaapiv1.ProjectConfig) error { var data []byte @@ -98,7 +106,13 @@ func ProjectsListGet(prjs *[]xaapiv1.ProjectConfig) error { } Log.Debugf("Result of /projects: %v", string(data[:])) - return json.Unmarshal(data, &prjs) + if err := json.Unmarshal(data, &prjs); err != nil { + return err + } + + sort.Sort(_PrjByLabel(*prjs)) + + return nil } // LogPost Helper to log a POST request |