Skip to content

momentohq/client-sdk-go

Folders and files

NameName
Last commit message
Last commit date
Nov 17, 2023
Dec 8, 2023
Sep 22, 2023
Dec 8, 2023
Nov 17, 2023
Dec 8, 2023
Dec 8, 2023
Dec 8, 2023
Dec 8, 2023
Mar 14, 2023
Feb 14, 2023
Jun 1, 2023
Mar 14, 2023
Feb 1, 2022
Sep 22, 2023
Sep 12, 2023
Jun 1, 2023
Dec 8, 2023
Mar 14, 2023

Repository files navigation

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!