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:
The ToKeyID
helper has generic support for types string
, []byte
, [16]byte
, uint64
, uint32
, int64
, and uint64
. When using a typed version of these it may be necessary to convert to one of these types first. See examples below:
A typed primitive:
github.com/gofrs/uuid/v5
UUID:
github.com/google/uuid
UUID:
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:
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.