/
crawl.go
36 lines (31 loc) · 1.08 KB
/
crawl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2023 cloudeng llc. All rights reserved.
// Use of this source code is governed by the Apache-2.0
// license that can be found in the LICENSE file.
package protocolsio
import (
"context"
"encoding/gob"
"cloudeng.io/file/content"
"cloudeng.io/webapi/operations"
"cloudeng.io/webapi/protocolsio/protocolsiosdk"
)
// NewProtocolCrawler creates a new instance of operations.Crawler
// that can be used to crawl/download protocols on protocols.io.
func NewProtocolCrawler(
ctx context.Context, checkpoint Checkpoint,
fopts FetcherOptions, popts PaginatorOptions, opts ...operations.Option) (*operations.Crawler[protocolsiosdk.ListProtocolsV3, protocolsiosdk.ProtocolPayload], error) {
fetcher, err := NewFetcher(fopts, opts...)
if err != nil {
return nil, err
}
paginator, err := NewPaginator(ctx, checkpoint, popts)
if err != nil {
return nil, err
}
scanner := operations.NewScanner(paginator, opts...)
crawler := operations.NewCrawler(scanner, fetcher)
return crawler, nil
}
func init() {
gob.Register(&content.Object[protocolsiosdk.ProtocolPayload, operations.Response]{})
}