Last active
December 20, 2015 00:49
-
-
Save tobz/6045042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Go through all the configured servers and organize them by category. | |
groups := make(map[string]map[string]interface{}, 0) | |
for _, s := range me.Configuration.Servers { | |
// Create the group entry if we don't already have one. | |
if _, ok := groups[s.Category]; !ok { | |
group := make(map[string]interface{}, 0) | |
servers := make([]map[string]string, 0) | |
group["servers"] = servers | |
groups[s.Category] = group | |
} | |
// Create a server entry and add it to the group. | |
server := make(map[string]string, 0) | |
server["internalName"] = s.InternalName | |
server["displayName"] = s.DisplayName | |
existingServers := groups[s.Category]["servers"].([]map[string]string) | |
existingServers = append(existingServers, server) | |
groups[s.Category]["servers"] = existingServers | |
} | |
// Wrap our result. | |
result := make(map[string]interface{}, 0) | |
result["groups"] = groups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment