Skip to content

Instantly share code, notes, and snippets.

@robherley
Last active June 8, 2022 17:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save robherley/8bd1326aed4cceb1d2d5b08bbc6e60c2 to your computer and use it in GitHub Desktop.
Sort by ID
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sort"
)
var handles = [...]string{
"jmillsy",
"bethanyj28",
"brittanyellich",
"eggyhead",
"jtamsut",
"konradpabjan",
"robherley",
"srryan",
"soelinn",
"yacaovsnc",
"pfleidi",
}
type Hubber struct {
ID int64 `json:"id"`
Login string `json:"login"`
}
func main() {
hubbers := make([]Hubber, len(handles))
for i := range handles {
resp, _ := http.Get(fmt.Sprintf("https://api.github.com/users/%s", handles[i]))
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &hubbers[i])
}
sort.Slice(hubbers, func(a, b int) bool {
return hubbers[a].ID < hubbers[b].ID
})
for i := range hubbers {
fmt.Printf("%v\n", hubbers[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment