Created
February 14, 2020 22:08
-
-
Save dragonsinth/cb7fbf38efbaf3a293eee32d46e81a36 to your computer and use it in GitHub Desktop.
Revisions
-
dragonsinth created this gist
Feb 14, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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 }