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
    Required
    Required
    Type
    context
    Description

    The context of the call, used for tracing.

  • Name
    key
    Required
    Required
    Type
    string
    Description

    The key that references value.

  • Name
    value
    Required
    Required
    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()
}