From b102e0c89608d2f166f0d9ca6555db1f4f5dee3c Mon Sep 17 00:00:00 2001 From: Anita Ruangrotsakun <138700973+anitarua@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:00:34 -0700 Subject: [PATCH] chore: add go sdk storage examples (#1081) * chore: add go sdk storage examples * add storage-related keywords to go sdk landing page * update wording Co-authored-by: pgautier404 --------- Co-authored-by: pgautier404 --- docs/cache/getting-started.mdx | 4 +- docs/sdks/go/index.md | 7 ++ docs/sdks/go/storage.mdx | 99 +++++++++++++++++++ docs/sdks/index.md | 1 + .../languages/golang-snippet-source-parser.ts | 8 +- 5 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 docs/sdks/go/storage.mdx diff --git a/docs/cache/getting-started.mdx b/docs/cache/getting-started.mdx index 2055c15ff..0ce2f7daa 100644 --- a/docs/cache/getting-started.mdx +++ b/docs/cache/getting-started.mdx @@ -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)) diff --git a/docs/sdks/go/index.md b/docs/sdks/go/index.md index 11dea0e62..56f33d071 100644 --- a/docs/sdks/go/index.md +++ b/docs/sdks/go/index.md @@ -21,9 +21,15 @@ keywords: - examples - resources - getting started + - quick start - server-side - go - golang + - storage + - persistence + - datastore + - database + - durable --- # Momento Go SDK @@ -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 diff --git a/docs/sdks/go/storage.mdx b/docs/sdks/go/storage.mdx new file mode 100644 index 000000000..b5444f00f --- /dev/null +++ b/docs/sdks/go/storage.mdx @@ -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= +``` + +## 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. + + + +## Create a new store in Momento Storage +Use this function to create a new store in your account. + + + + +## List the names of existing stores in your account +A simple list of the names of stores for the account. + + + +## Write an item to a store +A simple example of doing a put operation. + + + +## Read an item from a store +This is an example of a simple read operation to get an item from a store. + + + +## 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. + +::: diff --git a/docs/sdks/index.md b/docs/sdks/index.md index e72df3e70..644dac206 100644 --- a/docs/sdks/index.md +++ b/docs/sdks/index.md @@ -309,6 +309,7 @@ Momento server-side SDKs allow you to take advantage of Momento's low-latency Ca + diff --git a/plugins/example-code-snippets/src/examples/resolvers/source-parsers/languages/golang-snippet-source-parser.ts b/plugins/example-code-snippets/src/examples/resolvers/source-parsers/languages/golang-snippet-source-parser.ts index b59541dd1..b38f6cf6b 100644 --- a/plugins/example-code-snippets/src/examples/resolvers/source-parsers/languages/golang-snippet-source-parser.ts +++ b/plugins/example-code-snippets/src/examples/resolvers/source-parsers/languages/golang-snippet-source-parser.ts @@ -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 = [ - 'examples/doc-examples-go-apis.go', - ]; + const wholeFileExamplesDir = '.'; + const codeSnippetFiles: Array = ['examples/docs-examples/main.go']; super({ - // wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir), + wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir), snippetTypeParseOptions: new Map< ExampleSnippetType, RegexSnippetTypeOptions