inital commit
This commit is contained in:
12
comment.go
12
comment.go
@@ -28,25 +28,25 @@ type Comment struct {
|
||||
// Comments aren't paginated, so this iterator performs one fetch and then
|
||||
// yields each comment in document order; early termination still avoids
|
||||
// processing the rest of the slice.
|
||||
func (c *Client) SubmissionComments(ctx context.Context, id SubmissionID) iter.Seq2[*Comment, error] {
|
||||
return c.yieldComments(ctx, urls.Submission(int64(id)))
|
||||
func (c *Client) SubmissionComments(ctx context.Context, id SubmissionID, opts ...Option) iter.Seq2[*Comment, error] {
|
||||
return c.yieldComments(ctx, urls.Submission(int64(id)), opts)
|
||||
}
|
||||
|
||||
// JournalComments yields every comment on a journal page. Same iteration
|
||||
// shape as [Client.SubmissionComments].
|
||||
func (c *Client) JournalComments(ctx context.Context, id JournalID) iter.Seq2[*Comment, error] {
|
||||
return c.yieldComments(ctx, urls.Journal(int64(id)))
|
||||
func (c *Client) JournalComments(ctx context.Context, id JournalID, opts ...Option) iter.Seq2[*Comment, error] {
|
||||
return c.yieldComments(ctx, urls.Journal(int64(id)), opts)
|
||||
}
|
||||
|
||||
// yieldComments performs the single fetch shared by submission and journal
|
||||
// comment iterators, then yields parsed comments to the caller.
|
||||
func (c *Client) yieldComments(ctx context.Context, pageURL string) iter.Seq2[*Comment, error] {
|
||||
func (c *Client) yieldComments(ctx context.Context, pageURL string, opts []Option) iter.Seq2[*Comment, error] {
|
||||
return func(yield func(*Comment, error) bool) {
|
||||
var comments []*Comment
|
||||
err := c.fetch(ctx, pageURL, func(doc *goquery.Document) error {
|
||||
comments = parseComments(doc)
|
||||
return nil
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
yield(nil, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user