Go - Kv.Set()

Store a key value pair in a key value store.

import (
"context"
"fmt"
"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.KvStoreSet)
err := profiles.Set(context.Background(), "profile-1a2b3c", map[string]interface{}{
"name": "John Smith",
})
if err != nil {
fmt.Println(err)
}
nitric.Run()
}

Parameters

  • Name
    ctx
    Type
    context
    Description

    The context of the call, used for tracing.

  • Name
    key
    Type
    string
    Description

    The key that references value.

  • Name
    value
    Type
    map[string]interface{}
    Description

    A json serializable object that is stored as the value.

Examples

Set a key value pair

import (
"context"
"fmt"
"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.KvStoreSet)
err := profiles.Set(context.Background(), "profile-1a2b3c", map[string]interface{}{
"name": "John Smith",
})
if err != nil {
fmt.Println(err)
}
nitric.Run()
}
Last updated on Oct 11, 2024