Skip to content

Commit

Permalink
Update templated README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
schwern authored and Momento GitHub Actions Bot committed Feb 14, 2023
1 parent 0f385fe commit 1482da2
Showing 1 changed file with 0 additions and 95 deletions.
95 changes: 0 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<head>
<meta name="Momento Go Client Library Documentation" content="Go client software development kit for Momento Serverless Cache">
</head>
<img src="https://docs.momentohq.com/img/logo.svg" alt="logo" width="400"/>

[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-alpha.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)

# Momento Go Client Library


Go client SDK for Momento Serverless Cache: a fast, simple, pay-as-you-go caching solution without
any of the operational overhead required by traditional caching solutions!



## Getting Started :running:

Expand All @@ -39,91 +29,6 @@ Checkout our [examples](./examples/README.md) directory for complete examples of
Here is a quickstart you can use in your own project:

```go
package main

import (
"context"
"errors"
"log"
"time"

"github.com/momentohq/client-sdk-go/auth"
"github.com/momentohq/client-sdk-go/config"
"github.com/momentohq/client-sdk-go/momento"

"github.com/google/uuid"
)

func main() {
ctx := context.Background()
var credentialProvider, err = auth.NewEnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
if err != nil {
panic(err)
}

const (
cacheName = "my-test-cache"
itemDefaultTTLSeconds = 60
)

// Initializes Momento
client, err := momento.NewSimpleCacheClient(&momento.SimpleCacheClientProps{
Configuration: config.LatestLaptopConfig(),
CredentialProvider: credentialProvider,
DefaultTTL: itemDefaultTTLSeconds * time.Second,
})
if err != nil {
panic(err)
}

// Create Cache and check if CacheName exists
err = client.CreateCache(ctx, &momento.CreateCacheRequest{
CacheName: cacheName,
})
if err != nil {
var momentoErr momento.MomentoError
if errors.As(err, &momentoErr) {
if momentoErr.Code() != momento.AlreadyExistsError {
panic(err)
}
}
}

// Sets key with default TTL and gets value with that key
key := uuid.NewString()
value := uuid.NewString()
log.Printf("Setting key: %s, value: %s\n", key, value)
_, err = client.Set(ctx, &momento.SetRequest{
CacheName: cacheName,
Key: &momento.StringBytes{Text: key},
Value: &momento.StringBytes{Text: value},
})
if err != nil {
panic(err)
}

log.Printf("Getting key: %s\n", key)
resp, err := client.Get(ctx, &momento.GetRequest{
CacheName: cacheName,
Key: &momento.StringBytes{Text: key},
})
if err != nil {
panic(err)
}

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

// Permanently delete the cache
if err = client.DeleteCache(ctx, &momento.DeleteCacheRequest{CacheName: cacheName}); err != nil {
panic(err)
}
log.Printf("Cache named %s is deleted\n", cacheName)
}

```

Expand Down

0 comments on commit 1482da2

Please sign in to comment.