No description
Find a file
2026-03-08 16:03:06 +11:00
example/todo-cli Add todo-cli example application 2026-03-08 15:32:41 +11:00
.gitignore add to .gitignore 2026-03-08 15:54:44 +11:00
client.go Add core Go client library 2026-03-08 15:25:09 +11:00
client_test.go Add core Go client library 2026-03-08 15:25:09 +11:00
errors.go Add core Go client library 2026-03-08 15:25:09 +11:00
go.mod Add core Go client library 2026-03-08 15:25:09 +11:00
LICENSE add LICENSE 2026-03-08 15:55:43 +11:00
README.md add README 2026-03-08 16:03:06 +11:00
types.go Add core Go client library 2026-03-08 15:25:09 +11:00

datastore-client-go

Go client for the Datastore service — a DynamoDB-compatible JSON RPC API.

Installation

go get code.m.ac.nz/sophie/datastore-client-go

Usage

import datastore "code.m.ac.nz/sophie/datastore-client-go"

client := datastore.New(datastore.Config{
    Endpoint:  "http://localhost:8080/",
    Namespace: "my_tenant",
    JWT:       "eyJhbGciOiJSUzI1NiIs...",
})

Configuration

Field Description
Endpoint Base URL of the datastore service
Namespace Multi-tenant namespace (default: "default")
JWT Static bearer token for authentication
JWTProvider Function called per-request to obtain a token (takes precedence over JWT)
HTTPClient Custom *http.Client (default: http.DefaultClient)

API methods

Tables: CreateTable, DescribeTable, ListTables, DeleteTable, UpdateTable

Items: PutItem, GetItem, DeleteItem, UpdateItem

Query: Query, Scan

Batch: BatchWriteItem

Health: Health (no auth required)

Attribute values

datastore.String("hello")
datastore.Number("42")
datastore.Bool(true)
datastore.Null()
datastore.List(datastore.String("a"), datastore.String("b"))
datastore.Map(datastore.AttributeMap{"key": datastore.String("val")})

Error handling

All API errors implement the *DatastoreError base type. Use errors.As to check for specific error types:

out, err := client.GetItem(ctx, datastore.GetItemInput{...})
if err != nil {
    var notFound *datastore.ResourceNotFoundError
    if errors.As(err, &notFound) {
        // table does not exist
    }
    return err
}

Error types: ValidationError, ResourceNotFoundError, ResourceInUseError, ConditionalCheckFailedError, SerializationError, UnauthorizedError, AccessDeniedError, InternalServerError, MissingActionError, UnknownActionError.

Example

See example/todo-cli/ for a complete CLI app using this client.

# Set up environment
export DATASTORE_URL=http://localhost:8080/
export DATASTORE_JWT=<token>

# Run
go run ./example/todo-cli create-table
go run ./example/todo-cli add "Buy milk"
go run ./example/todo-cli list
go run ./example/todo-cli done <id>
go run ./example/todo-cli delete <id>