Go - Kv.Set()

Store a key value pair in a key value store.

import (
	"context"
	"fmt"

	"github.com/nitrictech/go-sdk/nitric"
)

func main() {
	// Initialize the KV service
	profiles, err := nitric.NewKv("profiles").Allow(nitric.KvStoreSet)
	if err != nil {
		return
	}

	err = profiles.Set(context.Background(), "profile-1a2b3c", map[string]interface{}{
		"name": "John Smith",
	})
	if err != nil {
		fmt.Println(err)
	}

	if err := nitric.Run(); err != nil {
		fmt.Println(err)
	}
}

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"
)

func main() {
	// Initialize the KV service
	profiles, err := nitric.NewKv("profiles").Allow(nitric.KvStoreSet)
	if err != nil {
		return
	}

	err = profiles.Set(context.Background(), "profile-1a2b3c", map[string]interface{}{
		"name": "John Smith",
	})
	if err != nil {
		fmt.Println(err)
	}

	if err := nitric.Run(); err != nil {
		fmt.Println(err)
	}
}