Created
February 14, 2020 22:08
-
-
Save dragonsinth/cb7fbf38efbaf3a293eee32d46e81a36 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
func GetFriends(ctx context.Context, user int64) (map[string]*User, error) { | |
// Produce | |
var friendIds []int64 | |
for it := GetFriendIds(user); ; { | |
if id, err := it.Next(ctx); err != nil { | |
if err == io.EOF { | |
break | |
} | |
return nil, fmt.Errorf("GetFriendIds %d: %w", user, err) | |
} else { | |
friendIds = append(friendIds, id) | |
} | |
} | |
// Map | |
ret := map[string]*User{} | |
for _, friendId := range friendIds { | |
if friend, err := GetUserProfile(ctx, friendId); err != nil { | |
return nil, fmt.Errorf("GetUserProfile %d: %w", friendId, err) | |
} else { | |
ret[friend.Name] = friend | |
} | |
} | |
return ret, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment