README

This Go SDK provides a type-safe client for the Portal DB API, generated using oapi-codegen.

Installation

go get github.com/buildwithgrove/path/portal-db/sdk/go

Quick Start

Click to expand Quick Start example
package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/buildwithgrove/path/portal-db/sdk/go"
)

func main() {
    // Create a new client with typed responses
    client, err := portaldb.NewClientWithResponses("http://localhost:3000")
    if err != nil {
        log.Fatal(err)
    }
    
    ctx := context.Background()
    
    // Example: Get public data
    resp, err := client.GetNetworksWithResponse(ctx, &portaldb.GetNetworksParams{})
    if err != nil {
        log.Fatal(err)
    }
    
    if resp.StatusCode() == 200 && resp.JSON200 != nil {
        networks := *resp.JSON200
        fmt.Printf("Found %d networks\n", len(networks))
    }
}

Authentication

For authenticated endpoints, add your JWT token to requests:

Click to expand Authentication example
import (
    "context"
    "net/http"
    
    "github.com/buildwithgrove/path/portal-db/sdk/go"
)

func authenticatedExample() {
    client, err := portaldb.NewClientWithResponses("http://localhost:3000")
    if err != nil {
        log.Fatal(err)
    }
    
    // Add JWT token to requests
    token := "your-jwt-token-here"
    ctx := context.Background()
    
    // Use RequestEditorFn to add authentication header
    requestEditor := func(ctx context.Context, req *http.Request) error {
        req.Header.Set("Authorization", "Bearer "+token)
        return nil
    }
    
    // Make authenticated request
    resp, err := client.GetPortalAccountsWithResponse(
        ctx, 
        &portaldb.GetPortalAccountsParams{}, 
        requestEditor,
    )
    if err != nil {
        log.Fatal(err)
    }
    
    if resp.StatusCode() == 200 && resp.JSON200 != nil {
        accounts := *resp.JSON200
        fmt.Printf("Found %d accounts\n", len(accounts))
    } else {
        fmt.Printf("Authentication failed: %d\n", resp.StatusCode())
    }
}

Query Features

The SDK supports PostgREST's powerful query features for filtering, selecting, and pagination.

Filtering and Selection

Click to expand Filtering and Selection example

Specific Resource Lookup

Click to expand Specific Resource Lookup example

RPC Functions

Access custom database functions via the RPC endpoint:

Click to expand RPC Functions example

Error Handling

Click to expand Error Handling example

Complete Example

A complete working example is available in the example/ directory:

  • example/main.go - Demonstrates basic SDK usage

  • example/go.mod - Module configuration with local replace directive

To run:

Development

This SDK was generated from the OpenAPI specification served by PostgREST.

To regenerate run the following make target while the PostgREST API is running:

Generated Files

  • models.go - Generated data models and type definitions

  • client.go - Generated API client methods and HTTP logic

  • go.mod - Go module definition

  • README.md - This documentation

Was this helpful?