Skip to content

Commit

Permalink
chore: add go sdk storage examples (#1081)
Browse files Browse the repository at this point in the history
* chore: add go sdk storage examples

* add storage-related keywords to go sdk landing page

* update wording

Co-authored-by: pgautier404 <[email protected]>

---------

Co-authored-by: pgautier404 <[email protected]>
  • Loading branch information
anitarua and pgautier404 authored Jul 17, 2024
1 parent 9e6b94c commit b102e0c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/cache/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ You can also install the Momento CLI locally (Linux, Windows, Mac) if desired. T
Ready to start writing some code? Check out our [SDKs](../sdks) page for a list of all of our supported languages. Each
SDK has a quick start for using Momento Cache or Topics. Here are direct links to a few of the most popular ones:

- [Node.js](../sdks/nodejs) ([cache](../sdks/nodejs/cache), [topics](../sdks/nodejs/topics)
- [Node.js](../sdks/nodejs) ([cache](../sdks/nodejs/cache), [topics](../sdks/nodejs/topics))
- [JavaScript Web SDK](../sdks/web) ([cache](../sdks/nodejs/cache), [topics](../sdks/nodejs/topics))
- [Python](../sdks/python) ([cache](../sdks/python/cache), [topics](../sdks/python/topics))
- [Java](../sdks/java) ([cache](../sdks/java/cache), [topics](../sdks/java/topics))
- [Go](../sdks/go) ([cache](../sdks/go/cache), [topics](../sdks/go/topics))
- [.NET](../sdks/dotnet) ([cache](../sdks/dotnet/cache), [topics](../sdks/dotnet/topics)
- [.NET](../sdks/dotnet) ([cache](../sdks/dotnet/cache), [topics](../sdks/dotnet/topics))
7 changes: 7 additions & 0 deletions docs/sdks/go/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ keywords:
- examples
- resources
- getting started
- quick start
- server-side
- go
- golang
- storage
- persistence
- datastore
- database
- durable
---

# Momento Go SDK
Expand All @@ -41,6 +47,7 @@ The source code can be found on GitHub: [momentohq/client-sdk-go](https://github

- [Getting started with Momento Cache in Go](./cache.mdx)
- [Getting started with Momento Topics in Go](./topics.mdx)
- [Getting started with Momento Storage in Go](./storage.mdx)
- [Go SDK Examples](https://github.com/momentohq/client-sdk-go/blob/main/examples/README.md): working example projects that illustrate how to use the Go SDK

## Integrations
Expand Down
99 changes: 99 additions & 0 deletions docs/sdks/go/storage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
sidebar_position: 3
sidebar_label: Storage
title: Getting started with Momento Storage in Go
description: Learn the basic building blocks for writing Go code to interact with Momento Storage.
keywords:
- momento
- cache
- caching
- topics
- pubsub
- pub/sub
- eda
- event-driven architecture
- redis
- serverless
- storage
- persistence
- datastore
- database
- durable
- sdk
- sdks
- api
- examples
- resources
- getting started
- quick start
- server-side
- go
- golang
---

import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock";
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl";

# Getting Started with Momento Storage in Go

If you need to get going quickly with Go and Momento Storage, this page contains the basic API calls you'll need. [Check the Go SDK examples](https://github.com/momentohq/client-sdk-go/tree/main/examples) for complete, working examples including build configuration files.

## Install the Momento SDK

The Momento SDK is available on Go Packages: [client-sdk-go](https://pkg.go.dev/github.com/momentohq/client-sdk-go).

:::tip
Visit [Go Packages](https://pkg.go.dev/github.com/momentohq/client-sdk-go) to find the latest available version of the SDK.
:::

Install the client library in an existing Go project:

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

## Set up your API key

You'll need a Momento API key to authenticate with Momento. You can get one from the [Momento Web Console](https://console.gomomento.com/api-keys).
Once you have your API key, store it in an environment variable so that the Momento client can consume it:

```
export MOMENTO_API_KEY=<your Momento API key here>
```

## Import libraries and connect to return a StorageClient object
This code sets up the main function, the necessary imports, and the StorageClient that will be used to interact with your store.

<SdkExampleCodeBlock language={'go'} file={'examples/storage-cheat-sheet/main.go'} />

## Create a new store in Momento Storage
Use this function to create a new store in your account.

<SdkExampleCodeBlock language={'go'} snippetId={'API_Storage_CreateStore'} />


## List the names of existing stores in your account
A simple list of the names of stores for the account.

<SdkExampleCodeBlock language={'go'} snippetId={'API_Storage_ListStores'} />

## Write an item to a store
A simple example of doing a put operation.

<SdkExampleCodeBlock language={'go'} snippetId={'API_Storage_Put'} />

## Read an item from a store
This is an example of a simple read operation to get an item from a store.

<SdkExampleCodeBlock language={'go'} snippetId={'API_Storage_Get'} />

## Running the code

You can find complete, working examples in the [Go SDK github repo examples directory](https://github.com/momentohq/client-sdk-go/tree/main/examples).

:::info
Beyond these basic API calls check out the [API reference page](/storage/develop/api-reference/index.mdx) for more information on the full assortment of Momento API calls.

:::
1 change: 1 addition & 0 deletions docs/sdks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ Momento server-side SDKs allow you to take advantage of Momento's low-latency Ca
<LinkButton text="Overview" link="/sdks/go"/>
<LinkButton text="Cache" link="/sdks/go/cache.html"/>
<LinkButton text="Topics" link="/sdks/go/topics.html"/>
<LinkButton text="Storage" link="/sdks/go/storage.html"/>
<LinkButton text="Examples" link="https://github.com/momentohq/client-sdk-go/blob/main/examples/README.md" openInNewTab="true" />
<LinkButton text="Packages" link="https://github.com/momentohq/client-sdk-go/releases" openInNewTab="true" />
<LinkButton text="Source Code" link="https://github.com/momentohq/client-sdk-go" openInNewTab="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import * as path from 'path';

export class GolangSnippetSourceParser extends RegexSnippetSourceParser {
constructor(repoSourceDir: string) {
// const wholeFileExamplesDir = 'examples/doc-example-files';
const codeSnippetFiles: Array<string> = [
'examples/doc-examples-go-apis.go',
];
const wholeFileExamplesDir = '.';
const codeSnippetFiles: Array<string> = ['examples/docs-examples/main.go'];
super({
// wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir),
wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir),
snippetTypeParseOptions: new Map<
ExampleSnippetType,
RegexSnippetTypeOptions
Expand Down

0 comments on commit b102e0c

Please sign in to comment.