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/goQuick 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
Specific Resource Lookup
RPC Functions
Access custom database functions via the RPC endpoint:
Error Handling
Complete Example
A complete working example is available in the example/ directory:
example/main.go- Demonstrates basic SDK usageexample/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 definitionsclient.go- Generated API client methods and HTTP logicgo.mod- Go module definitionREADME.md- This documentation
Related Documentation
API Documentation: ../../api/README.md
OpenAPI Specification:
../../api/openapi/openapi.json
Was this helpful?
