The Go SDK is currently in experimental status. If you would like to provide feedback, please reach out to us with your suggestions and comments on our Discord.
Go - Kv.Get()
Get a value from a key value store.
import (
"context"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/keyvalue"
)
func main() {
// Initialize the KV service
profiles := nitric.NewKv("profiles").Allow(keyvalue.KvStoreGet)
profile, err := profiles.Get(context.Background(), "profile-1a2b3c")
if err != nil {
// handle error
}
// do something with the profile
nitric.Run()
}
Parameters
- Name
ctx
- Required
- Required
- Type
- context
- Description
The context of the call, used for tracing.
- Name
key
- Required
- Required
- Type
- string
- Description
The key that references the key value pair that should be retrieved.
Examples
Get a key value pair
import (
"context"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/keyvalue"
)
func main() {
// Initialize the KV service
profiles := nitric.NewKv("profiles").Allow(keyvalue.KvStoreGet)
profile, err := profiles.Get(context.Background(), "profile-1a2b3c")
if err != nil {
// handle error
}
// do something with the profile
nitric.Run()
}