Skip to content

Commit 9fcbdd4

Browse files
authored
Merge pull request #21 from planetlabs/doc-updates
Doc updates
2 parents bb64c92 + d241799 commit 9fcbdd4

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

crawler/crawler.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/tschaub/workgroup"
1717
)
1818

19+
// RecursionType informs the crawler how to treat linked resources.
20+
// None will only call the visitor for the first resource. Children
21+
// will call the visitor for all child catalogs, collections, and items.
22+
// All will call the visitor for parent resources as well as child resources.
1923
type RecursionType string
2024

2125
const (
@@ -113,6 +117,10 @@ func resolveURL(baseUrl string, resourceUrl string) (string, error) {
113117
return resolved.String(), nil
114118
}
115119

120+
// Visitor is called for each resource during crawling.
121+
//
122+
// The resource location (URL or file path) is passed as the first argument.
123+
// Any returned error will stop crawling and be returned by Crawl.
116124
type Visitor func(string, Resource) error
117125

118126
// Crawler crawls STAC resources.
@@ -168,7 +176,9 @@ func New(visitor Visitor, options ...*Options) *Crawler {
168176

169177
// Crawl calls the visitor for each resolved resource.
170178
//
171-
// The resource can be a file path or a URL.
179+
// The resource can be a file path or a URL. Any error returned by visitor
180+
// will stop crawling and be returned by this function. Context cancellation
181+
// will also stop crawling and the context error will be returned.
172182
func (c *Crawler) Crawl(ctx context.Context, resource string) error {
173183
resourceUrl, isFilepath, err := normalizeUrl(resource)
174184
if err != nil {

crawler/resource.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const (
55
extensionsKey = "stac_extensions"
66
)
77

8+
// ResourceType indicates the document-level STAC resource type.
89
type ResourceType string
910

1011
const (
11-
Item = ResourceType("item")
12-
Catalog = ResourceType("catalog")
13-
Collection = ResourceType("collection")
12+
Item ResourceType = "item"
13+
Catalog ResourceType = "catalog"
14+
Collection ResourceType = "collection"
1415
)
1516

1617
// Resource represents a STAC catalog, collection, or item.

validator/errors.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type ValidationError struct {
1818
Resource crawler.Resource
1919
}
2020

21+
// GoString provides additional detail about the validation error.
22+
//
23+
// Called when the # flag is used with the %v verb as in fmt.Printf("%#v", err).
2124
func (err *ValidationError) GoString() string {
2225
return fmt.Sprintf("invalid %s: %s\n%s", err.Resource.Type(), err.Location, err.ValidationError.GoString())
2326
}

validator/validator.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ func schemaUrl(version string, resourceType crawler.ResourceType) string {
151151

152152
// Validate validates a STAC resource.
153153
//
154-
// The resource can be a path to a local file or a URL.
154+
// The resource can be a path to a local file or a URL. Validation will stop
155+
// with the first invalid resource and the resulting ValidationError will be
156+
// returned. Context cancellation will also stop validation and the context
157+
// error will be returned.
155158
func (v *Validator) Validate(ctx context.Context, resource string) error {
156159
c := crawler.New(v.validate, &crawler.Options{
157160
Concurrency: v.concurrency,

validator/validator_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ func TestSuite(t *testing.T) {
9090

9191
func ExampleValidator_Validate_children() {
9292
v := validator.New(&validator.Options{
93-
Concurrency: 1,
94-
Recursion: crawler.Children,
93+
Recursion: crawler.Children,
9594
})
9695

9796
err := v.Validate(context.Background(), "testdata/cases/v1.0.0/catalog-with-item-missing-id.json")
@@ -107,8 +106,7 @@ func ExampleValidator_Validate_children() {
107106

108107
func ExampleValidator_Validate_single() {
109108
v := validator.New(&validator.Options{
110-
Concurrency: 1,
111-
Recursion: crawler.None,
109+
Recursion: crawler.None,
112110
})
113111

114112
err := v.Validate(context.Background(), "testdata/cases/v1.0.0/item-missing-id.json")

0 commit comments

Comments
 (0)