|
|
|
|
|
by tidwall
173 days ago
|
|
Or this. func fetchUser(id int) (user User, err error) {
resp, err := http.Get(fmt.Sprintf("https://api.example.com/users/%d", id))
if err != nil {
return user, err
}
defer resp.Body.Close()
return user, json.NewDecoder(resp.Body).Decode(&user)
}
|
|
Also those variables are returned even if you don't explicitly return them, which feels a little unintuitive.