Last active
June 8, 2022 17:25
-
-
Save robherley/8bd1326aed4cceb1d2d5b08bbc6e60c2 to your computer and use it in GitHub Desktop.
Sort by ID
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
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