client-sdk-go

module
v1.28.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2024 License: Apache-2.0

README

logo

project status project stability

Momento Go Client Library

Momento Cache is a fast, simple, pay-as-you-go caching solution without any of the operational overhead required by traditional caching solutions. This repo contains the source code for the Momento Go client library.

To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.

Packages

The Momento Golang SDK is available here on github: momentohq/client-sdk-go.

go get github.com/momentohq/client-sdk-go

Usage

Checkout our examples directory for complete examples of how to use the SDK.

Here is a quickstart you can use in your own project:

package main

import (
	"context"
	"log"
	"time"

	"github.com/google/uuid"
	"github.com/momentohq/client-sdk-go/auth"
	"github.com/momentohq/client-sdk-go/config"
	"github.com/momentohq/client-sdk-go/config/logger"
	"github.com/momentohq/client-sdk-go/momento"
	"github.com/momentohq/client-sdk-go/responses"
)

func main() {
	context := context.Background()
	configuration := config.LaptopLatestWithLogger(logger.NewNoopMomentoLoggerFactory()).WithClientTimeout(15 * time.Second)
	credentialProvider, err := auth.NewEnvMomentoTokenProvider("MOMENTO_API_KEY")
	if err != nil {
		panic(err)
	}
	defaultTtl := time.Duration(9999)

	client, err := momento.NewCacheClient(configuration, credentialProvider, defaultTtl)
	if err != nil {
		panic(err)
	}

	key := uuid.NewString()
	value := uuid.NewString()
	log.Printf("Setting key: %s, value: %s\n", key, value)
	_, _ = client.Set(context, &momento.SetRequest{
		CacheName: "cache-name",
		Key:       momento.String(key),
		Value:     momento.String(value),
		Ttl:       time.Duration(9999),
	})

	if err != nil {
		panic(err)
	}

	resp, err := client.Get(context, &momento.GetRequest{
		CacheName: "cache-name",
		Key:       momento.String(key),
	})
	if err != nil {
		panic(err)
	}

	switch r := resp.(type) {
	case *responses.GetHit:
		log.Printf("Lookup resulted in cache HIT. value=%s\n", r.ValueString())
	case *responses.GetMiss:
		log.Printf("Look up did not find a value key=%s", key)
	}
}

Getting Started and Documentation

Documentation is available on the Momento Docs website.

Examples

Check out full working code in the examples directory of this repository!

Developing

If you are interested in contributing to the SDK, please see the CONTRIBUTING docs.


For more info, visit our website at https://gomomento.com!

Directories

Path Synopsis
Package config provides pre-built configurations.
Package config provides pre-built configurations.
Package momento represents API CacheClient interface accessors including control/data operations, errors, operation requests and responses for the SDK.
Package momento represents API CacheClient interface accessors including control/data operations, errors, operation requests and responses for the SDK.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL