KV Store in Go
- Platform:
- Fastly Compute
- Language:
- Go
- Repo:
- https://github.com/fastly/compute-starter-kits/tree/main/starter-kits/go/kv-store
Use this starter
Using the Fastly CLI, create a new project using this starter somewhere on your computer:
$ fastly compute init --from=starter-kit/go/kv-storeDeploying the project to Fastly
Note that Fastly Services have to have unique names within a Fastly Account.
To create and deploy to a new Fastly Service run the command and follow the instructions:
fastly compute publishThat is it, we now have a Fastly Service, a Fastly KV Store and have them linked together!
You can view real-time logs for the Fastly Service by running:
fastly log-tailAdding entries to the KV Store
It is possible to add key-value pairs to an KV Store using the Fastly CLI like so:
fastly kv-store-entry create --store-id=$FASTLY_KV_STORE_ID --key-name=$KEY --value=$VALUEFor example, here is how you could add to the KV Store named my-store a key named readme whose value is the contents of README.md:
fastly kv-store-entry create --store-id="$(fastly kv-store list --json | jq -r '.Data[]|select(.Name=="my-store").ID')" --key-name="readme" --value="$(cat README.md)"Next steps
Starters are a good way to bootstrap a project. For more specific use cases, and answers to common problems, try our library of code examples.