Skip to content

Go

Our API Reference has generic examples in every supported language, and we strive to make the experience of each SDK very similar. However, there are some things specific to the Go SDK that we want to call out here.

Key Path Helper

The github.com/StatelyCloud/go-sdk/stately.ToKeyID(value) function can be used to format an ID value (especially a UUID) correctly to include in a key path:

1
kp := "/movie-"+stately.ToKeyID(movieID)+"/actor-"+stately.ToKeyID(actorID)

Checking an Item’s Type

Many client APIs return a *stately.Item, but you want to know exactly what type it is. You can use standard Go type checks for this:

1
if movie, ok := item.(*schema.Movie); ok {
2
// it's a movie
3
}
4
5
switch v := item.(type) {
6
case *schema.Movie:
7
// it's a movie
8
case *schema.Character:
9
// it's a character
10
}

Protobuf

The Go types generated from your schema are actually google.golang.org/protobuf objects. They expose each of their fields as properties, but also have a method version that is nil-safe. For example if you have a name field, the Go object will have a Name property and a GetName() method. The method version will return an empty string even if called on a nil pointer.

UUIDs

UUIDs are represented as []byte of length 16. You can use the github.com/gofrs/uuid/v5 or github.com/google/uuid package to convert them to and from strings.