Small Go client and CLI for querying and downloading products from the Alaska Satellite Facility (ASF) Search API.
- Wraps the ASF search endpoint with typed options instead of raw query strings.
- Handles authentication (bearer, basic, or custom headers) and redirect-safe HTTP client setup.
- Downloads matching products concurrently with sensible error messages.
- Ships a simple CLI (
asfcli) for quick searches or scripted downloads.
- Library: add
github.com/robert-malhotra/go-asfto your module andgo getas usual. - CLI:
go install ./cmd/asfcli
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/robert-malhotra/go-asf/pkg/asf"
)
func main() {
ctx := context.Background()
client := asf.NewClient(asf.WithAuthToken("<ASF_TOKEN>"))
opts := asf.SearchOptions{
Platforms: []asf.Platform{asf.PlatformSentinel1},
ProcessingLevel: []asf.ProcessingLevel{asf.ProcessingLevelSLC},
Start: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
End: time.Date(2025, 1, 31, 23, 59, 59, 0, time.UTC),
IntersectsWith: "POLYGON ((-64.8 32.3, -65.5 18.3, -80.3 25.2, -64.8 32.3))",
MaxResults: 10,
}
products, err := client.Search(ctx, opts)
if err != nil {
log.Fatalf("search failed: %v", err)
}
fmt.Printf("found %d products\n", len(products))
// Download the first product (requires auth token)
if len(products) > 0 {
if err := client.Download(ctx, "./downloads", products[0]); err != nil {
log.Fatalf("download failed: %v", err)
}
}
}- Set
ASF_TOKENif you need authenticated downloads. - Common searches:
asfcli search --platform Sentinel-1 --processing-level SLC --start 2024-01-01T00:00:00Z --end 2025-01-31T23:59:59Zasfcli search --platform Sentinel-1 --beam-mode IW --intersects "POLYGON ((-64.8 32.3, -65.5 18.3, -80.3 25.2, -64.8 32.3))" --max-results 5
- Output formats:
- Table (default):
--output text - JSON:
--output json
- Table (default):
- Download results: append
--download-dir ./datato fetch all matched products.
- Anonymous searches work for most filters.
- Downloads often require an ASF bearer token: set
ASF_TOKENor pass--tokento the CLI. - Library helpers:
asf.WithAuthToken(token)asf.BasicAuth(user, pass)asf.HeaderAuth(map[string]string{...})
- Unit tests:
go test ./... pkg/asf/live_test.gohits the real ASF API; it runs without auth for search validation. Download coverage in that test is skipped unlessASF_TOKENis set.