Skip to content

Instantly share code, notes, and snippets.

@tobz
Last active December 20, 2015 00:49
Show Gist options
  • Save tobz/6045042 to your computer and use it in GitHub Desktop.
Save tobz/6045042 to your computer and use it in GitHub Desktop.
// 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