# README
StatelyDB SDK for Go
This is the Go SDK for StatelyDB.
Getting started:
Disclaimer:
We're still in an invite-only preview mode - if you're interested, please reach out to [email protected].
When you join the preview program, we'll set you up with a few bits of information:
STATELY_CLIENT_ID
- a client identifier so we know what client you are.STATELY_CLIENT_SECRET
- a sensitive secret that lets your applications authenticate with the API.- A store ID that identifies which store in your organization you're using.
- Access to our in-depth Getting Started Guide.
Begin by following our Getting Started Guide which will help you define, generate, and publish a DB schema so that it can be used.
Install the SDK
go get -u github.com/StatelyCloud/go-sdk
Usage:
After Defining Schema, be sure to generate a schema in a go module where it can be referenced. For the purposes of this readme ths will be github.com/Project/Package/schema
.
Instantiate an Authenticated Client
To use the client from a Go application:
import (
"github.com/StatelyCloud/go-sdk/stately"
"github.com/Project/Package/schema"
)
func main() {
ctx := context.Background() // TODO: Use a real context please
// Create a client. This will use the environment variables
// STATELY_CLIENT_ID and STATELY_CLIENT_SECRET for your client.
client, err := schema.NewClient(ctx, 12345)
if err != nil { ... }
// Alternatively:
client, err := schema.NewClient(ctx, *stately.Options{
ClientID: "myClientID",
ClientSecret: "myClientSecret",
})
if err != nil { ... }
}
Using a client:
Once you have an authenticated client, you can use reference your item types (where they live in your schema module) and use the client!
func PutMyItem(ctx context.Context, client stately.Client) error {
item := &schema.Person{
Handle: "i_am_jane",
Name: "Jane Doe",
}
putResult, err := client.Put(ctx, item)
if err != nil { ... }
getResult, err := client.Get(ctx, "/user-i_am_jane")
if err != nil { ... }
// etc.
}