Go - Kv.Get()

Get a value from 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.KvStoreGet)
	if err != nil {
		return
	}

	profile, err := profiles.Get(context.Background(), "profile-1a2b3c")
	// do something with the profile

	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 the key value pair that should be retrieved.

Examples

Get 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.KvStoreGet)
	if err != nil {
		return
	}

	profile, err := profiles.Get(context.Background(), "profile-1a2b3c")
	// do something with the profile

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