Next Return the next item in the result set and advance the iterator. Advancing the iterator may require fetching a new page.
()
| 717 | // Next Return the next item in the result set and advance the iterator. |
| 718 | // Advancing the iterator may require fetching a new page. |
| 719 | func (ci *CommentIterator) Next() *Comment { |
| 720 | if ci.Err != nil { |
| 721 | return nil |
| 722 | } |
| 723 | |
| 724 | comment := ci.message.Comments[ci.itemIdx] |
| 725 | if ci.itemIdx+1 < len(ci.message.Comments) { |
| 726 | // We still have an item left in the currently cached page |
| 727 | ci.itemIdx++ |
| 728 | } else { |
| 729 | if ci.message.IsLastPage() { |
| 730 | ci.Err = errDone |
| 731 | } else { |
| 732 | // There are still more pages to fetch, so fetch the next page and |
| 733 | // cache it |
| 734 | ci.message, ci.Err = ci.client.GetComments( |
| 735 | ci.idOrKey, ci.pageSize, ci.message.NextStartAt()) |
| 736 | // NOTE(josh): we don't deal with the error now, we just cache it. |
| 737 | // HasNext() will return false and the caller can check the error |
| 738 | // afterward. |
| 739 | ci.itemIdx = 0 |
| 740 | } |
| 741 | } |
| 742 | return &comment |
| 743 | } |
| 744 | |
| 745 | // IterComments returns an iterator over paginated comments within an issue |
| 746 | func (client *Client) IterComments(idOrKey string, pageSize int) *CommentIterator { |
no test coverage detected