README

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

Installation

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

Quick Start

chevron-rightClick to expand Quick Start examplehashtag
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:

chevron-rightClick to expand Authentication examplehashtag
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

chevron-rightClick to expand Filtering and Selection examplehashtag

Specific Resource Lookup

chevron-rightClick to expand Specific Resource Lookup examplehashtag

RPC Functions

Access custom database functions via the RPC endpoint:

chevron-rightClick to expand RPC Functions examplehashtag

Error Handling

chevron-rightClick to expand Error Handling examplehashtag

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?