Skip to content

Add Go docs #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ StylesPath = "vale/styles"

Vocab = docs
Packages = Google
IgnoredScopes = code, tt, img, url, a
IgnoredScopes = code, tt, img, url, a, text.frontmatter
SkippedScopes = script, style, pre, figure, code
MinAlertLevel = warning

# Treat MDX as Markdown
[formats]
mdx = md

[*.{md, mdx}]
[*.{md,mdx}]

# Ignore react components starting with export const
# Ignore code blocks in triple backticks
Expand Down
41 changes: 41 additions & 0 deletions api-reference/go/datasets/As.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: As
sidebarTitle: As
icon: layer-group
---

```go
func As[T proto.Message](seq iter.Seq2[[]byte, error]) iter.Seq2[T, error]
```

Convert a sequence of bytes into a sequence of `proto.Message`.

Useful to convert the output of [`Datapoints.Query`](/api-reference/go/datasets/Datapoints.Query) into a sequence of `proto.Message`.

## Parameters

<ParamField path="seq" type="iter.Seq2[[]byte, error]">
The sequence of bytes to convert
</ParamField>

## Returns

A sequence of `proto.Message` or an error if any.

<RequestExample>
```go Go
import (
"time"
datasets "github.com/tilebox/tilebox-go/datasets/v1"
"github.com/tilebox/tilebox-go/query"
)

startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
queryInterval := query.NewTimeInterval(startDate, endDate)

seq := datasets.As[*v1.Sentinel1Sar](
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
)
```
</RequestExample>
41 changes: 41 additions & 0 deletions api-reference/go/datasets/Collect.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Collect
sidebarTitle: Collect
icon: layer-group
---

```go
func Collect[K any](seq iter.Seq2[K, error]) ([]K, error)
```

Convert any sequence into a slice.

It return an error if any of the elements in the sequence has a non-nil error.

## Parameters

<ParamField path="seq" type="iter.Seq2[[]K, error]">
The sequence of bytes to convert
</ParamField>

## Returns

A slice of `K` or an error if any.

<RequestExample>
```go Go
import (
"time"
datasets "github.com/tilebox/tilebox-go/datasets/v1"
"github.com/tilebox/tilebox-go/query"
)

startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
queryInterval := query.NewTimeInterval(startDate, endDate)

datapoints, err := datasets.Collect(datasets.As[*v1.Sentinel1Sar](
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
))
```
</RequestExample>
43 changes: 43 additions & 0 deletions api-reference/go/datasets/CollectAs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: CollectAs
sidebarTitle: CollectAs
icon: layer-group
---

```go
func CollectAs[T proto.Message](seq iter.Seq2[[]byte, error]) ([]T, error)
```

Convert a sequence of bytes into a slice of `proto.Message`.

Useful to convert the output of [`Datapoints.Query`](/api-reference/go/datasets/Datapoints.Query) into a slice of `proto.Message`.

This a convenience function for `Collect(As[T](seq))`.

## Parameters

<ParamField path="seq" type="iter.Seq2[[]byte, error]">
The sequence of bytes to convert
</ParamField>

## Returns

A slice of `proto.Message` or an error if any.

<RequestExample>
```go Go
import (
"time"
datasets "github.com/tilebox/tilebox-go/datasets/v1"
"github.com/tilebox/tilebox-go/query"
)

startDate := time.Date(2014, 10, 4, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2021, 2, 24, 0, 0, 0, 0, time.UTC)
queryInterval := query.NewTimeInterval(startDate, endDate)

datapoints, err := datasets.CollectAs[*v1.Sentinel1Sar](
client.Datapoints.Query(ctx, collectionID, datasets.WithTemporalExtent(queryInterval)),
)
```
</RequestExample>
37 changes: 37 additions & 0 deletions api-reference/go/datasets/Collections.Create.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Client.Collections.Create
sidebarTitle: Collections.Create
icon: layer-group
---

```go
func (collectionClient) Create(
ctx context.Context,
datasetID uuid.UUID,
collectionName string,
) (*datasets.Collection, error)
```

Create a collection in the dataset.

## Parameters

<ParamField path="datasetID" type="uuid.UUID">
The id of the dataset
</ParamField>
<ParamField path="collectionName" type="string">
The name of the collection
</ParamField>

## Returns

The created collection object.

<RequestExample>
```go Go
collection, err := client.Collections.Create(ctx,
datasetID,
"My-collection",
)
```
</RequestExample>
43 changes: 43 additions & 0 deletions api-reference/go/datasets/Collections.Get.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Client.Collections.Get
sidebarTitle: Collections.Get
icon: layer-group
---

```go
func (collectionClient) Get(
ctx context.Context,
datasetID uuid.UUID,
name string,
) (*datasets.Collection, error)
```

Get a dataset by its slug.

## Parameters

<ParamField path="datasetID" type="uuid.UUID">
The id of the dataset
</ParamField>
<ParamField path="name" type="string">
The name of the collection
</ParamField>

## Returns

The created collection object.

<RequestExample>
```go Go
collection, err := client.Collections.Get(ctx,
datasetID,
"My-collection",
)
```
</RequestExample>

## Errors

<ParamField path="not_found" type="No such dataset">
The specified dataset does not exist.
</ParamField>
37 changes: 37 additions & 0 deletions api-reference/go/datasets/Collections.GetOrCreate.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Client.Collections.GetOrCreate
sidebarTitle: Collections.GetOrCreate
icon: layer-group
---

```go
func (collectionClient) GetOrCreate(
ctx context.Context,
datasetID uuid.UUID,
name string,
) (*datasets.Collection, error)
```

Get or create a collection by its name. If the collection does not exist, it will be created.

## Parameters

<ParamField path="datasetID" type="uuid.UUID">
The id of the dataset
</ParamField>
<ParamField path="name" type="string">
The name of the collection
</ParamField>

## Returns

A collection object.

<RequestExample>
```go Go
collection, err := client.Collections.GetOrCreate(ctx,
datasetID,
"My-collection",
)
```
</RequestExample>
38 changes: 38 additions & 0 deletions api-reference/go/datasets/Collections.List.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Client.Collections.List
sidebarTitle: Collections.List
icon: layer-group
---

```go
func (collectionClient) List(
ctx context.Context,
datasetID uuid.UUID,
) ([]*datasets.Collection, error)
```

List the available collections in a dataset.

## Parameters

<ParamField path="datasetID" type="uuid.UUID">
The id of the dataset
</ParamField>

## Returns

A list of collection objects.

<RequestExample>
```go Go
collections, err := client.Collections.List(ctx,
datasetID,
)
```
</RequestExample>

## Errors

<ParamField path="not_found" type="No such dataset">
The specified dataset does not exist.
</ParamField>
42 changes: 42 additions & 0 deletions api-reference/go/datasets/Datapoints.Delete.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Client.Datapoints.Delete
sidebarTitle: Datapoints.Delete
icon: layer-group
---

```go
func (datapointClient) Delete(
ctx context.Context,
collectionID uuid.UUID,
datapoints any,
) (int64, error)
```

Delete data points from a collection.

Data points are identified and deleted by their ids.

## Parameters

<ParamField path="collectionID" type="uuid.UUID">
The id of the collection
</ParamField>
<ParamField path="datapoints" type="[]proto.Message">
The datapoints to delete from the collection
</ParamField>

## Returns

The number of data points that were deleted.

<RequestExample>
```go Go
var datapoints []*v1.Sentinel1Sar
// assuming the slice is filled with datapoints

numDeleted, err := client.Datapoints.Delete(ctx,
collectionID,
datapoints,
)
```
</RequestExample>
40 changes: 40 additions & 0 deletions api-reference/go/datasets/Datapoints.DeleteIDs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Client.Datapoints.DeleteIDs
sidebarTitle: Datapoints.DeleteIDs
icon: layer-group
---

```go
func (datapointClient) DeleteIDs(
ctx context.Context,
collectionID uuid.UUID,
datapointIDs []uuid.UUID,
) (int64, error)
```

Delete data points from a collection.

## Parameters

<ParamField path="collectionID" type="uuid.UUID">
The id of the collection
</ParamField>
<ParamField path="datapointIDs" type="[]uuid.UUID">
The ids of the data points to delete from the collection
</ParamField>

## Returns

The number of data points that were deleted.

<RequestExample>
```go Go
numDeleted, err := client.Datapoints.DeleteIDs(ctx,
collectionID,
[]uuid.UUID{
uuid.MustParse("0195c87a-49f6-5ffa-e3cb-92215d057ea6"),
uuid.MustParse("0195c87b-bd0e-3998-05cf-af6538f34957"),
},
)
```
</RequestExample>
Loading
Loading