mirror of
https://github.com/gofiber/storage.git
synced 2025-09-27 04:46:08 +08:00

Some checks failed
Release Drafter (All) / changes (push) Has been cancelled
Sync docs / sync-docs (push) Has been cancelled
Tests ArangoDB / Tests (1.19.x) (push) Has been cancelled
Tests ArangoDB / Tests (1.20.x) (push) Has been cancelled
Tests ArangoDB / Tests (1.21.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.19.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.20.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.21.x) (push) Has been cancelled
Tests Badger / Tests (1.19.x) (push) Has been cancelled
Tests Badger / Tests (1.20.x) (push) Has been cancelled
Tests Badger / Tests (1.21.x) (push) Has been cancelled
Tests Bbolt / Tests (1.19.x) (push) Has been cancelled
Tests Bbolt / Tests (1.20.x) (push) Has been cancelled
Tests Bbolt / Tests (1.21.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.22.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.23.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.24.x) (push) Has been cancelled
Tests CloudflareKV / Tests (1.21.x) (push) Has been cancelled
Tests CloudflareKV / Tests (1.22.x) (push) Has been cancelled
Tests Coherence / Tests (1.19.x) (push) Has been cancelled
Tests Coherence / Tests (1.20.x) (push) Has been cancelled
Tests Coherence / Tests (1.21.x) (push) Has been cancelled
Tests Coherence / Tests (1.22.x) (push) Has been cancelled
Tests Couchbase / Tests (1.22.x) (push) Has been cancelled
Tests Couchbase / Tests (1.23.x) (push) Has been cancelled
Tests Couchbase / Tests (1.24.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.22.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.23.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.24.x) (push) Has been cancelled
Tests Etcd / Tests (1.19.x) (push) Has been cancelled
Tests Etcd / Tests (1.20.x) (push) Has been cancelled
Tests Etcd / Tests (1.21.x) (push) Has been cancelled
Tests LevelDB / Tests (1.23.x) (push) Has been cancelled
Tests LevelDB / Tests (1.24.x) (push) Has been cancelled
Tests Memcache / Tests (1.19.x) (push) Has been cancelled
Tests Memcache / Tests (1.20.x) (push) Has been cancelled
Tests Memcache / Tests (1.21.x) (push) Has been cancelled
Tests Local Storage / Tests (1.19.x) (push) Has been cancelled
Tests Local Storage / Tests (1.20.x) (push) Has been cancelled
Tests Local Storage / Tests (1.21.x) (push) Has been cancelled
Tests Minio / Tests (1.22.x) (push) Has been cancelled
Tests Minio / Tests (1.23.x) (push) Has been cancelled
Tests Minio / Tests (1.24.x) (push) Has been cancelled
Tests Local Storage / Tests (1.22.x) (push) Has been cancelled
Tests Mongodb / Tests (1.22.x) (push) Has been cancelled
Tests Mongodb / Tests (1.23.x) (push) Has been cancelled
Tests Mongodb / Tests (1.24.x) (push) Has been cancelled
Tests MSSQL / Tests (1.19.x) (push) Has been cancelled
Tests MSSQL / Tests (1.20.x) (push) Has been cancelled
Tests MSSQL / Tests (1.21.x) (push) Has been cancelled
Tests MySQL / Tests (1.22.x) (push) Has been cancelled
Tests MySQL / Tests (1.23.x) (push) Has been cancelled
Tests MySQL / Tests (1.24.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.22.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.23.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.24.x) (push) Has been cancelled
Tests Neo4j / Tests (1.23.x) (push) Has been cancelled
Tests pebble / Tests (1.19.x) (push) Has been cancelled
Tests pebble / Tests (1.20.x) (push) Has been cancelled
Tests pebble / Tests (1.21.x) (push) Has been cancelled
Tests Postgres / Tests (1.22.x) (push) Has been cancelled
Tests Postgres / Tests (1.23.x) (push) Has been cancelled
Tests Postgres / Tests (1.24.x) (push) Has been cancelled
Tests Redis / Tests (1.19.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.19.x, 7.x) (push) Has been cancelled
Tests Redis / Tests (1.20.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.20.x, 7.x) (push) Has been cancelled
Tests Redis / Tests (1.21.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.21.x, 7.x) (push) Has been cancelled
Tests Ristretto / Tests (1.19.x) (push) Has been cancelled
Tests Ristretto / Tests (1.20.x) (push) Has been cancelled
Tests Ristretto / Tests (1.21.x) (push) Has been cancelled
Tests Rueidis / Tests (1.20.x, 6.x) (push) Has been cancelled
Tests Rueidis / Tests (1.20.x, 7.x) (push) Has been cancelled
Tests Rueidis / Tests (1.21.x, 6.x) (push) Has been cancelled
Tests Rueidis / Tests (1.21.x, 7.x) (push) Has been cancelled
Tests S3 / Tests (1.21.x) (push) Has been cancelled
Tests S3 / Tests (1.22.x) (push) Has been cancelled
Tests S3 / Tests (1.23.x) (push) Has been cancelled
Tests ScyllaDb / Tests (1.20.x) (push) Has been cancelled
Tests ScyllaDb / Tests (1.21.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.19.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.20.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.21.x) (push) Has been cancelled
Tests Valkey / Tests (1.23.x, 7.x) (push) Has been cancelled
Tests Valkey / Tests (1.23.x, 8.x) (push) Has been cancelled
Release Drafter (All) / release-drafter (push) Has been cancelled
5.3 KiB
5.3 KiB
id, title
id | title |
---|---|
dynamodb | DynamoDB |
A DynamoDB storage driver using aws/aws-sdk-go-v2.
Note: If config fields of credentials not given, credentials are using from the environment variables, ~/.aws/credentials, or EC2 instance role. If config fields of credentials given, credentials are using from config. Look at: specifying credentials
Note: Requires Go 1.19 and above
Table of Contents
Signatures
func New(config Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *awsdynamodb.Client
Installation
DynamoDB is tested on the 2 last Go versions with support for modules. So make sure to initialize one first if you didn't do that yet:
go mod init github.com/<user>/<repo>
And then install the dynamodb implementation:
go get github.com/gofiber/storage/dynamodb/v2
Examples
Import the storage package.
import "github.com/gofiber/storage/dynamodb/v2"
You can use the following possibilities to create a storage:
// Initialize dynamodb
store := dynamodb.New(dynamodb.Config{
})
Config
type Config struct {
// Region of the DynamoDB service you want to use.
// Valid values: https://docs.aws.amazon.com/general/latest/gr/rande.html#ddb_region.
// E.g. "us-west-2".
// Optional (read from shared config file or environment variable if not set).
// Environment variable: "AWS_REGION".
Region string
// Name of the DynamoDB table.
// Optional ("fiber_storage" by default).
Table string
// CustomEndpoint allows you to set a custom DynamoDB service endpoint.
// This is especially useful if you're running a "DynamoDB local" Docker container for local testing.
// Typical value for the Docker container: "http://localhost:8000".
// See https://hub.docker.com/r/amazon/dynamodb-local/.
// Optional ("" by default)
Endpoint string
// Credentials overrides AWS access key and AWS secret access key. Not recommended.
//
// Optional. Default is Credentials{}
Credentials Credentials
// The maximum number of times requests that encounter retryable failures should be attempted.
//
// Optional. Default is 3
MaxAttempts int
// Reset clears any existing keys in existing Bucket
//
// Optional. Default is false
Reset bool
// ReadCapacityUnits of the table.
// Only required when the table doesn't exist yet and is created by gokv.
// Optional (5 by default, which is the same default value as when creating a table in the web console)
// 25 RCUs are included in the free tier (across all tables).
// For example calculations, see https://github.com/awsdocs/amazon-dynamodb-developer-guide/blob/c420420a59040c5b3dd44a6e59f7c9e55fc922ef/doc_source/HowItWorks.ProvisionedThroughput.
// For limits, see https://github.com/awsdocs/amazon-dynamodb-developer-guide/blob/c420420a59040c5b3dd44a6e59f7c9e55fc922ef/doc_source/Limits.md#capacity-units-and-provisioned-throughput.md#provisioned-throughput.
ReadCapacityUnits int64
// ReadCapacityUnits of the table.
// Only required when the table doesn't exist yet and is created by gokv.
// Optional (5 by default, which is the same default value as when creating a table in the web console)
// 25 RCUs are included in the free tier (across all tables).
// For example calculations, see https://github.com/awsdocs/amazon-dynamodb-developer-guide/blob/c420420a59040c5b3dd44a6e59f7c9e55fc922ef/doc_source/HowItWorks.ProvisionedThroughput.
// For limits, see https://github.com/awsdocs/amazon-dynamodb-developer-guide/blob/c420420a59040c5b3dd44a6e59f7c9e55fc922ef/doc_source/Limits.md#capacity-units-and-provisioned-throughput.md#provisioned-throughput.
WriteCapacityUnits int64
// If the table doesn't exist yet, gokv creates it.
// If WaitForTableCreation is true, gokv will block until the table is created, with a timeout of 15 seconds.
// If the table still doesn't exist after 15 seconds, an error is returned.
// If WaitForTableCreation is false, gokv returns the client immediately.
// In the latter case you need to make sure that you don't read from or write to the table before it's created,
// because otherwise you will get ResourceNotFoundException errors.
// Optional (true by default).
WaitForTableCreation *bool
}
type Credentials struct {
AccessKey string
SecretAccessKey string
}
Default Config
var ConfigDefault = Config{
Table: "fiber_storage",
Credentials: Credentials{},
MaxAttempts: 3,
Reset: false,
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
WaitForTableCreation: aws.Bool(true),
}