
# Go

Start with the [REST guide](../rest.md) to get a Platform API token. This example uses Go's standard library; no client generation or extra packages are needed.

Save as `main.go`:

```go
package main

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "net/url"
    "os"
    "time"
)

type catalog struct {
    ID string `json:"catalogId"`
}
type page struct {
    Catalogs []catalog `json:"catalogs"`
    NextPageToken string `json:"nextPageToken"`
}
type detail struct {
    ID string `json:"catalogId"`
    Description string `json:"description"`
}

func main() {
    token := os.Getenv("CR_RECONSTRUCT_API_TOKEN")
    if token == "" { log.Fatal("set CR_RECONSTRUCT_API_TOKEN") }
    base := "https://reconstruct.dev/api/v1/platform"
    client := &http.Client{Timeout: 10 * time.Second}

    get := func(path string, result any) error {
        req, err := http.NewRequest(http.MethodGet, base+path, nil)
        if err != nil { return err }
        req.Header.Set("Authorization", "Bearer "+token)
        resp, err := client.Do(req)
        if err != nil { return err }
        defer resp.Body.Close()
        if resp.StatusCode != http.StatusOK {
            return fmt.Errorf("API returned %s", resp.Status)
        }
        return json.NewDecoder(resp.Body).Decode(result)
    }

    var first page
    if err := get("/catalogs?pageSize=10", &first); err != nil { log.Fatal(err) }
    for _, item := range first.Catalogs {
        var info detail
        if err := get("/catalogs/"+url.PathEscape(item.ID), &info); err != nil {
            log.Fatal(err)
        }
        fmt.Println(info.ID, info.Description)
    }
    if first.NextPageToken != "" { fmt.Println("Next page token:", first.NextPageToken) }
}
```

Run `go run main.go`. Send `nextPageToken` as the URL-encoded `pageToken` query parameter to continue through the catalog.
