diff --git a/storage_versioned_docs/version-badger_v1.x.x/README.md b/storage_versioned_docs/version-badger_v1.x.x/README.md new file mode 100644 index 00000000000..d5ba9f3e305 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/README.md @@ -0,0 +1,72 @@ +--- +title: 👋 Welcome +description: 📦 Premade storage drivers for 🚀 Fiber. +sidebar_position: 1 +--- + +

+ Fiber + Fiber +
+ +# 📦 Storage + + + + + + + + + + +

+ +Premade storage drivers that implement the [`Storage`](https://github.com/gofiber/storage/blob/main/storage.go) interface, designed to be used with various [Fiber middlewares](https://github.com/gofiber/fiber/tree/master/middleware). + +```go +// Storage interface for communicating with different database/key-value +// providers. Visit https://github.com/gofiber/storage for more info. +type Storage interface { + // Get gets the value for the given key. + // `nil, nil` is returned when the key does not exist + Get(key string) ([]byte, error) + + // Set stores the given value for the given key along + // with an expiration value, 0 means no expiration. + // Empty key or value will be ignored without an error. + Set(key string, val []byte, exp time.Duration) error + + // Delete deletes the value for the given key. + // It returns no error if the storage does not contain the key, + Delete(key string) error + + // Reset resets the storage and delete all keys. + Reset() error + + // Close closes the storage and will stop any running garbage + // collectors and open connections. + Close() error +} +``` + +## 📑 Storage Implementations + +- [ArangoDB](./arangodb/README.md) +- [AzureBlob](./azureblob/README.md) +- [Badger](./badger/README.md) +- [Bbolt](./bbolt) +- [Couchbase](./couchbase/README.md) +- [DynamoDB](./dynamodb/README.md) +- [Etcd](./etcd/README.md) +- [Memcache](./memcache/README.md) +- [Memory](./memory/README.md) +- [MongoDB](./mongodb/README.md) +- [MSSQL](./mssql/README.md) +- [MySQL](./mysql/README.md) +- [Pebble](./pebble/README.md) +- [Postgres](./postgres/README.md) +- [Redis](./redis/README.md) +- [S3](./s3/README.md) +- [SQLite3](./sqlite3/README.md) + diff --git a/storage_versioned_docs/version-badger_v1.x.x/arangodb/README.md b/storage_versioned_docs/version-badger_v1.x.x/arangodb/README.md new file mode 100644 index 00000000000..ce8352bb08c --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/arangodb/README.md @@ -0,0 +1,118 @@ +--- +id: arangodb +title: ArangoDB +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=arangodb*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-arangodb.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A ArangoDB storage driver using `arangodb/go-driver` and [arangodb/go-driver](https://github.com/arangodb/go-driver). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() driver.Client +``` +### Installation +ArangoDB is tested on the 2 last (1.14/1.15) [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the mysql implementation: +```bash +go get github.com/gofiber/storage/arangodb +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/arangodb" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := arangodb.New() + +// Initialize custom config +store := arangodb.New(arangodb.Config{ + Host: "http://127.0.0.1", + Port: 8529, + Database: "fiber", + Collection: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, +}) +``` + +### Config +```go +type Config struct { + // Host name where the DB is hosted + // + // Optional. Default is "http://127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 8529 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Collection name + // + // Optional. Default is "fiber_storage" + Collection string + + // Reset clears any existing keys in existing collection + // + // Optional. Default is false + Reset bool + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration +} +``` + +### Default Config +Used only for optional fields +```go +var ConfigDefault = Config{ + Host: "http://127.0.0.1", + Port: 8529, + Database: "fiber", + Collection: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/azureblob/README.md b/storage_versioned_docs/version-badger_v1.x.x/azureblob/README.md new file mode 100644 index 00000000000..1a18a95891d --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/azureblob/README.md @@ -0,0 +1,112 @@ +--- +id: azureblob +title: Azure Blob +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=azureblob*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-azureblob.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +[Azure Blob storage](https://azure.microsoft.com/en-us/products/storage/blobs/#overview) is Microsoft's object storage solution for the cloud. + +> NOTE: Go **1.18** or later is required. Source: [link](https://github.com/Azure/azure-sdk-for-go/blob/main/README.md) + +### Table of Contents + +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures + +```go +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() *azblob.Client +``` + +### Installation + +Azure blob storage driver is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: + +```bash +go mod init github.com// +``` + +And then install the azure blob implementation: + +```bash +go get github.com/gofiber/storage/azureblob +``` + +### Examples + +Import the storage package. + +```go +import "github.com/gofiber/storage/azureblob" +``` + +You can use the following possibilities to create a storage: + +```go +// Initialize default config +store := azureblob.New() + +// Initialize custom config +store := azureblob.New(azureblob.Config{ + Account: "test", + Container: "test", + Credentials: Credentials{ + Account: "test", + Key: "YXp1cml0ZWtleQo=", + }, +}) +``` + +### Config + +```go +type Config struct { + // Storage account name. + Account string + // Container name. + Container string + // Storage endpoint. + // Optional. Default: "https://STORAGEACCOUNTNAME.blob.core.windows.net" + Endpoint string + // Request timeout. + // Optional. Default is 0 (no timeout) + RequestTimeout time.Duration + // Reset clears any existing keys in existing container. + // Optional. Default is false + Reset bool + // 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 +} +``` + +### Default Config + +```go +var ConfigDefault = Config{ + Account: "", + Container: "", + Endpoint: "", + RequestTimeout: 0, + Reset: false, + MaxAttempts: 3, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/badger/README.md b/storage_versioned_docs/version-badger_v1.x.x/badger/README.md new file mode 100644 index 00000000000..d80cd01d65d --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/badger/README.md @@ -0,0 +1,117 @@ +--- +id: badger +title: Badger +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=badger*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-badger.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A fast key-value DB using [dgraph-io/badger](https://github.com/dgraph-io/badger) + +### Table of Contents + +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures + +```go +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() *badger.DB +``` + +### Installation + +Badger is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: + +```bash +go mod init github.com// +``` + +And then install the badger implementation: + +```bash +go get github.com/gofiber/storage/badger +``` + +### Examples + +Import the storage package. + +```go +import "github.com/gofiber/storage/badger" +``` + +You can use the following possibilities to create a storage: + +```go +// Initialize default config +store := badger.New() + +// Initialize custom config +store := badger.New(badger.Config{ + Database: "./fiber.badger", + Reset: false, + GCInterval: 10 * time.Second, +}) +``` + +### Config + +```go +type Config struct { + // Database name + // + // Optional. Default is "./fiber.badger" + Database string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration + + // BadgerOptions is a way to set options in badger + // + // Optional. Default is badger.DefaultOptions("./fiber.badger") + BadgerOptions badger.Options + + // Logger is the default logger used by badger + // + // Optional. Default is nil + Logger badger.Logger + + // UseLogger define if any logger will be used + // + // Optional. Default is false + UseLogger bool +} +``` + +### Default Config + +```go +var ConfigDefault = Config{ + Database: "./fiber.badger", + Reset: false, + GCInterval: 10 * time.Second, + BadgerOptions: badger.DefaultOptions("./fiber.badger").WithLogger(nil), + Logger: nil, + UseLogger: false, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/bbolt/README.md b/storage_versioned_docs/version-badger_v1.x.x/bbolt/README.md new file mode 100644 index 00000000000..b0eb3046390 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/bbolt/README.md @@ -0,0 +1,103 @@ +--- +id: bbolt +title: Bbolt +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=bbolt*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-bbolt.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Bbolt storage driver using [etcd-io/bbolt](https://github.com/etcd-io/bbolt). Bolt is a pure Go key/value store inspired by [Howard Chu's](https://twitter.com/hyc_symas) [LMDB project](https://www.symas.com/symas-embedded-database-lmdb). The goal of the project is to provide a simple, fast, and reliable database for projects that don't require a full database server such as Postgres or MySQL. + + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *bbolt.DB +``` +### Installation +Bbolt is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the s3 implementation: +```bash +go get github.com/gofiber/storage/bbolt +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/bbolt" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := bbolt.New() + +// Initialize custom config +store := bbolt.New(bbolt.Config{ + Database: "my_database.db", + Bucket: "my-bucket", + Reset: false, +}) +``` + +### Config +```go +// Config defines the config for storage. +type Config struct { + // Database path + // + // Optional. Default is "fiber.db" + Database string + + // Bbolt bucket name + // + // Optional. Default is "fiber_storage" + Bucket string + + // Timeout is the amount of time to wait to obtain a file lock. + // Only available on Darwin and Linux. + // + // Optional. Default is 60 * time.Second. + Timeout time.Duration + + // Open database in read-only mode. + // + // Optional. Default is false + ReadOnly bool + + // Reset clears any existing keys in existing Bucket + // + // Optional. Default is false + Reset bool +} +``` + +### Default Config +```go +// ConfigDefault is the default config +var ConfigDefault = Config{ + Database: "fiber.db", + Bucket: "fiber_storage", + Timeout: 60 * time.Second, + ReadOnly: false, + Reset: false, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/couchbase/README.md b/storage_versioned_docs/version-badger_v1.x.x/couchbase/README.md new file mode 100644 index 00000000000..3739255a76d --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/couchbase/README.md @@ -0,0 +1,92 @@ +--- +id: couchbase +title: Couchbase +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=couchbase*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-couchbase.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Couchbase storage driver using [couchbase/gocb](https://github.com/couchbase/gocb). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *gocb.Cluster +``` +### Installation +Couchbase is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the Couchbase implementation: +```bash +go get github.com/gofiber/storage/couchbase +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/couchbase" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := couchbase.New() + +// Initialize Couchbase storage with custom config +store := couchbase.New(couchbase.Config{ + Host: "127.0.0.1:8091", + Username: "", + Password: "", + Bucket: 0, + ConnectionTimeout: 3* time.Second, + KVTimeout: 1* time.Second, +}) +``` + +### Config +```go +type Config struct { + // The application username to Connect to the Couchbase cluster + Username string + // The application password to Connect to the Couchbase cluster + Password string + // The connection string for the Couchbase cluster + Host string + // The name of the bucket to Connect to + Bucket string + // The timeout for connecting to the Couchbase cluster + ConnectionTimeout time.Duration + // The timeout for performing operations on the Couchbase cluster + KVTimeout time.Duration +} +``` + +### Default Config +```go +// ConfigDefault is the default config +var ConfigDefault = Config{ + Host: "127.0.0.1:8091", + Username: "admin", + Password: "123456", + Bucket: "fiber_storage", + ConnectionTimeout: 3 * time.Second, + KVTimeout: 1 * time.Second, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/dynamodb/README.md b/storage_versioned_docs/version-badger_v1.x.x/dynamodb/README.md new file mode 100644 index 00000000000..38be3fb927a --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/dynamodb/README.md @@ -0,0 +1,143 @@ +--- +id: dynamodb +title: DynamoDB +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=dynamodb*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-dynamodb.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A DynamoDB storage driver using [aws/aws-sdk-go-v2](https://github.com/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](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials) + +.... + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + + +### Signatures +```go +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](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the dynamodb implementation: +```bash +go get github.com/gofiber/storage/dynamodb +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/dynamodb" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize dynamodb +store := dynamodb.New(dynamodb.Config{ + +}) +``` + +### Config +```go +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 +```go +var ConfigDefault = Config{ + Table: "fiber_storage", + Credentials: Credentials{}, + MaxAttempts: 3, + Reset: false, + ReadCapacityUnits: 5, + WriteCapacityUnits: 5, + WaitForTableCreation: aws.Bool(true), +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/etcd/README.md b/storage_versioned_docs/version-badger_v1.x.x/etcd/README.md new file mode 100644 index 00000000000..11c128df4fc --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/etcd/README.md @@ -0,0 +1,85 @@ +--- +id: etcd +title: Etcd +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=etcd*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-etcd.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Etcd storage driver using [`etcd-io/etcd`](https://github.com/etcd-io/etcd). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *clientv3.Client +``` + +### Installation +Etcd is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the etcd implementation: +```bash +go get github.com/gofiber/storage/etcd +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/etcd" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := etcd.New() + +// Initialize custom config +store := etcd.New(Config{ + Endpoints: []string{"localhost:2379"}, +}) + +``` + +### Config +```go +type Config struct { + // Endpoints is a list of URLs. + Endpoints []string + // DialTimeout is the timeout for failing to establish a connection. + DialTimeout time.Duration + // Username is a username for authentication. + Username string + // Password is a password for authentication. + Password string + // TLS holds the client secure credentials, if any. + TLS *tls.Config +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + Endpoints: []string{"localhost:2379"}, + DialTimeout: 2 * time.Second, + Username: "", + Password: "", + TLS: nil, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/memcache/README.md b/storage_versioned_docs/version-badger_v1.x.x/memcache/README.md new file mode 100644 index 00000000000..07336693132 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/memcache/README.md @@ -0,0 +1,80 @@ +--- +id: memcache +title: Memcache +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=memcache*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memcache.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Memcache storage driver using [`bradfitz/gomemcache`](https://github.com/bradfitz/gomemcache). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *mc.Client +``` + +### Installation +Memory is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the memory implementation: +```bash +go get github.com/gofiber/storage/memory +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/memcache" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := memcache.New() + +// Initialize custom config +store := memcache.New(memcache.Config{ + Servers: "localhost:11211", +}) +``` + +### Config +```go +type Config struct { + // Server list divided by , + // i.e. server1:11211, server2:11212 + // + // Optional. Default is "127.0.0.1:11211" + Servers string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + Servers: "127.0.0.1:11211", +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/memory/README.md b/storage_versioned_docs/version-badger_v1.x.x/memory/README.md new file mode 100644 index 00000000000..469cb90ce55 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/memory/README.md @@ -0,0 +1,76 @@ +--- +id: memory +title: Memory +--- + + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=memory*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memory.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +An in-memory storage driver. + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + + +### Signatures +```go +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() map[string]entry +``` + +### Installation +Memory is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the memory implementation: +```bash +go get github.com/gofiber/storage/memory +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/memory" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := memory.New() + +// Initialize custom config +store := memory.New(memory.Config{ + GCInterval: 10 * time.Second, +}) +``` + +### Config +```go +type Config struct { + // Time before deleting expired keys + // + // Default is 10 * time.Second + GCInterval time.Duration +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + GCInterval: 10 * time.Second, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/mongodb/README.md b/storage_versioned_docs/version-badger_v1.x.x/mongodb/README.md new file mode 100644 index 00000000000..6efdea99872 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/mongodb/README.md @@ -0,0 +1,126 @@ +--- +id: mongodb +title: MongoDB +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=mongodb*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mongodb.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A MongoDB storage driver using [mongodb/mongo-go-driver](https://github.com/mongodb/mongo-go-driver). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *mongo.Database +``` +### Installation +MongoDB is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the mongodb implementation: +```bash +go get github.com/gofiber/storage/mongodb +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/mongodb" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := mongodb.New() + +// Initialize custom config +store := mongodb.New(mongodb.Config{ + Host: "127.0.0.1", + Port: 27017, + Database: "fiber", + Collection: "fiber_storage", + Reset: false, +}) + +// Initialize custom config using connection string +store := mongodb.New(mongodb.Config{ + ConnectionURI: "mongodb://user:password@127.0.0.1:27017", + Database: "fiber", + Collection: "fiber_storage", + Reset: false, +}) + +``` + +### Config +```go +type Config struct { + // Connection string to use for DB. Will override all other authentication values if used + // + // Optional. Default is "" + ConnectionURI string + + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 27017 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Collection name + // + // Optional. Default is "fiber_storage" + Collection string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + ConnectionURI: "", + Host: "127.0.0.1", + Port: 27017, + Database: "fiber", + Collection: "fiber_storage", + Reset: false, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/mssql/README.md b/storage_versioned_docs/version-badger_v1.x.x/mssql/README.md new file mode 100644 index 00000000000..5c37e93b313 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/mssql/README.md @@ -0,0 +1,144 @@ +--- +id: mssql +title: MSSQL +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=mssql*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mssql.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A MSSQL storage driver using [microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *sql.DB +``` +### Installation +MSSQL is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the mssql implementation: +```bash +go get github.com/gofiber/storage/mssql +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/mssql" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := mssql.New() + +// Initialize custom config +store := mssql.New(mssql.Config{ + Host: "127.0.0.1", + Port: 1433, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, + SslMode: "disable", +}) + +// Initialize custom config using connection string +store := mssql.New(mssql.Config{ + ConnectionURI: "sqlserver://user:password@localhost:1433?database=fiber" + Reset: false, + GCInterval: 10 * time.Second, +}) +``` + +### Config +```go +// Config defines the config for storage. +type Config struct { + // Connection string to use for DB. Will override all other authentication values if used + // + // Optional. Default is "" + ConnectionURI string + + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 1433 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Instance name + // + // Optional. Default is "" + Instance string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Table name + // + // Optional. Default is "fiber_storage" + Table string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration + + // The SSL mode for the connection + // + // Optional. Default is "disable" + SslMode string +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + ConnectionURI: "", + Host: "127.0.0.1", + Port: 1433, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, + SslMode: "disable", +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/mysql/README.md b/storage_versioned_docs/version-badger_v1.x.x/mysql/README.md new file mode 100644 index 00000000000..793ed3b285a --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/mysql/README.md @@ -0,0 +1,144 @@ +--- +id: mysql +title: MySQL +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=mysql*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mysql.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A MySQL storage driver using `database/sql` and [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *sql.DB +``` +### Installation +MySQL is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the mysql implementation: +```bash +go get github.com/gofiber/storage/mysql +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/mysql" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := mysql.New() + +// Initialize custom config +store := mysql.New(mysql.Config{ + Host: "127.0.0.1", + Port: 3306, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, +}) + +// Initialize custom config using connection string +store := mysql.New(mysql.Config{ + ConnectionURI: ":@tcp(:)/" + Reset: false, + GCInterval: 10 * time.Second, +}) + +// Initialize custom config using sql db connection +db, _ := sql.Open("mysql", ":@tcp(:)/") +store := mysql.New(mysql.Config{ + Db: db, + Reset: false, + GCInterval: 10 * time.Second, +}) +``` + +### Config +```go +type Config struct { + // DB Will override ConnectionURI and all other authentication values if used + // + // Optional. Default is nil + Db *sql.DB + + // Connection string to use for DB. Will override all other authentication values if used + // + // Optional. Default is "" + ConnectionURI string + + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 3306 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Table name + // + // Optional. Default is "fiber_storage" + Table string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + ConnectionURI: "", + Host: "127.0.0.1", + Port: 3306, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/pebble/README.md b/storage_versioned_docs/version-badger_v1.x.x/pebble/README.md new file mode 100644 index 00000000000..eb1e0dddaba --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/pebble/README.md @@ -0,0 +1,92 @@ +--- +id: pebble +title: Pebble +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=pebble*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-pebble.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A fast key-value DB using [cockroachdb/pebble](https://github.com/cockroachdb/pebble) + +### Table of Contents + +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures + +```go +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() *badger.DB +``` + +### Installation + +Pebble is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +Note: This step is only required if you don't have an existing module. + +And then install the Pebble implementation: + +```bash +go get github.com/gofiber/storage/pebble +``` + +### Examples + +Import the storage package. + +```go +import "github.com/gofiber/storage/pebble" +``` + +You can use the following possibilities to create a storage: + +```go +// Initialize default config +store := pebble.New() + +// Initialize custom config +store := pebble.New(pebble.Config{ + Path: "db", + WriteOptions: &pebble.WriteOptions{}, +}) +``` + +### Config + +```go +type Config struct { + // Database name + // + // Optional. Default is "./db" + Path string + + // Pass write options during write operations + // + // Optional. Default is nil + WriteOptions &pebble.WriteOptions{} +} +``` + +### Default Config + +```go +var ConfigDefault = Config{ + Path: "db", + WriteOptions: &pebble.WriteOptions{}, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/postgres/README.md b/storage_versioned_docs/version-badger_v1.x.x/postgres/README.md new file mode 100644 index 00000000000..e5f419938f9 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/postgres/README.md @@ -0,0 +1,135 @@ +--- +id: postgres +title: Postgres +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=postgres*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-postgres.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Postgres storage driver using [jackc/pgx](https://github.com/jackc/pgx). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *pgxpool.Pool +``` +### Installation +Postgres is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the postgres implementation: +```bash +go get github.com/gofiber/storage/postgres/v2 +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/postgres/v2" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := postgres.New() + +// Initialize custom config +store := postgres.New(postgres.Config{ + Db: dbPool, + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, +}) +``` + +### Config +```go +// Config defines the config for storage. +type Config struct { + // DB pgxpool.Pool object will override connection uri and other connection fields + // + // Optional. Default is nil + DB *pgxpool.Pool + + // Connection string to use for DB. Will override all other authentication values if used + // + // Optional. Default is "" + ConnectionURI string + + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 5432 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Table name + // + // Optional. Default is "fiber_storage" + Table string + + // The SSL mode for the connection + // + // Optional. Default is "disable" + SSLMode string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration +} +``` + +### Default Config +```go +// ConfigDefault is the default config +var ConfigDefault = Config{ + ConnectionURI: "", + Host: "127.0.0.1", + Port: 5432, + Database: "fiber", + Table: "fiber_storage", + SSLMode: "disable", + Reset: false, + GCInterval: 10 * time.Second, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/redis/README.md b/storage_versioned_docs/version-badger_v1.x.x/redis/README.md new file mode 100644 index 00000000000..1d5586cc94f --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/redis/README.md @@ -0,0 +1,193 @@ +--- +id: redis +title: Redis +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=redis*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-redis.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Redis storage driver using [go-redis/redis](https://github.com/go-redis/redis). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() redis.UniversalClient +``` +### Installation +Redis is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the redis implementation: +```bash +go get github.com/gofiber/storage/redis/v2 +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/redis/v2" +``` + +You can use the one of the following options to create a Redis Storage: +```go +// Initialize default config +store := redis.New() + +// Initialize custom config +store := redis.New(redis.Config{ + Host: "127.0.0.1", + Port: 6379, + Username: "", + Password: "", + Database: 0, + Reset: false, + TLSConfig: nil, + PoolSize: 10 * runtime.GOMAXPROCS(0), +}) + +// Initialize Redis Failover Client +store := redis.New(redis.Config{ + MasterName: "master-name", + Addrs: []string{":6379"}, +}) + +// Initialize Redis Cluster Client +store := redis.New(redis.Config{ + Addrs: []string{":6379", ":6380"}, +}) + +// Create a client with support for TLS +cer, err := tls.LoadX509KeyPair("./client.crt", "./client.key") +if err != nil { + log.Println(err) + return +} +tlsCfg := &tls.Config{ + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: true, + Certificates: []tls.Certificate{cer}, +} +store = redis.New(redis.Config{ + URL: "redis://:@127.0.0.1:6379/", + TLSConfig: tlsCfg, + Reset: false, +}) + +// Create a client with a Redis URL with all information. +store = redis.New(redis.Config{ + URL: "redis://:@127.0.0.1:6379/", + Reset: false, +}) +``` + +### Config +```go +type Config struct { + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 6379 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database to be selected after connecting to the server. + // + // Optional. Default is 0 + Database int + + // URL standard format Redis URL. If this is set all other config options, Host, Port, Username, Password, Database have no effect. + // + // Example: redis://:@localhost:6379/ + // Optional. Default is "" + URL string + + // Either a single address or a seed list of host:port addresses, this enables FailoverClient and ClusterClient + // + // Optional. Default is []string{} + Addrs []string + + // MasterName is the sentinel master's name + // + // Optional. Default is "" + MasterName string + + // ClientName will execute the `CLIENT SETNAME ClientName` command for each conn. + // + // Optional. Default is "" + ClientName string + + // SentinelUsername + // + // Optional. Default is "" + SentinelUsername string + + // SentinelPassword + // + // Optional. Default is "" + SentinelPassword string + + // Reset clears any existing keys in existing Collection + // + // Optional. Default is false + Reset bool + + // TLS Config to use. When set TLS will be negotiated. + // + // Optional. Default is nil + TLSConfig *tls.Config + + // Maximum number of socket connections. + // + // Optional. Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS. + PoolSize int +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + Host: "127.0.0.1", + Port: 6379, + Username: "", + Password: "", + URL: "", + Database: 0, + Reset: false, + TLSConfig: nil, + PoolSize: 10 * runtime.GOMAXPROCS(0), + Addrs: []string{}, + MasterName: "", + ClientName: "", + SentinelUsername: "", + SentinelPassword: "", +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/ristretto/README.md b/storage_versioned_docs/version-badger_v1.x.x/ristretto/README.md new file mode 100644 index 00000000000..ed3e22a303e --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/ristretto/README.md @@ -0,0 +1,84 @@ +--- +id: ristretto +title: Ristretto +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=ristretto*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-ristretto.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A Memory-bound storage driver using [`dgraph-io/ristretto`](https://github.com/dgraph-io/ristretto). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + + +### Signatures +```go +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() *ristretto.Cache +``` + +### Installation +Ristretto is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the ristretto implementation: +```bash +go get github.com/gofiber/storage/ristretto +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/ristretto" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := ristretto.New() + +// Initialize custom config +store := ristretto.New(ristretto.Config{ + NumCounters: 1e7, // number of keys to track frequency of (10M). + MaxCost: 1 << 30, // maximum cost of cache (1GB). + BufferItems: 64, // number of keys per Get buffer. +}) +``` + +### Config +```go +type Config struct { + // NumCounters number of keys to track frequency of (10M). + NumCounters int64 + + // MaxCost maximum cost of cache (1GB). + MaxCost int64 + + // BufferItems number of keys per Get buffer. + BufferItems int64 +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + NumCounters: 1e7, + MaxCost: 1 << 30, + BufferItems: 64, + DefaultCost: 1, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/s3/README.md b/storage_versioned_docs/version-badger_v1.x.x/s3/README.md new file mode 100644 index 00000000000..49ffe762568 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/s3/README.md @@ -0,0 +1,118 @@ +--- +id: s3 +title: S3 +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=s3*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-s3.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A S3 storage driver using [aws/aws-sdk-go-v2](https://github.com/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](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials) + + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *s3.Client +``` +### Installation +S3 is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the s3 implementation: +```bash +go get github.com/gofiber/storage/s3 +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/s3" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := s3.New() + +// Initialize custom config +store := s3.New(s3.Config{ + Bucket: "my-bucket-url", + Endpoint: "my-endpoint", + Region: "my-region", + Reset: false, +}) +``` + +### Config +```go +// Config defines the config for storage. +type Config struct { + // S3 bucket name + Bucket string + + // AWS endpoint + Endpoint string + + // AWS region + Region string + + // Request timeout + // + // Optional. Default is 0 (no timeout) + RequestTimeout time.Duration + + // Reset clears any existing keys in existing Bucket + // + // Optional. Default is false + Reset bool + + // 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 + +} + +type Credentials struct { + AccessKey string + SecretAccessKey string +} +``` + +### Default Config +The default configuration lacks Bucket, Region, and Endpoint which are all required and must be overwritten: +```go +// ConfigDefault is the default config +var ConfigDefault = Config{ + Bucket: "", + Region: "", + Endpoint: "", + Credentials: Credentials{}, + MaxAttempts: 3, + RequestTimeout: 0, + Reset: false, +} +``` diff --git a/storage_versioned_docs/version-badger_v1.x.x/sqlite3/README.md b/storage_versioned_docs/version-badger_v1.x.x/sqlite3/README.md new file mode 100644 index 00000000000..844007f60f0 --- /dev/null +++ b/storage_versioned_docs/version-badger_v1.x.x/sqlite3/README.md @@ -0,0 +1,119 @@ +--- +id: sqlite3 +title: SQLite3 +--- + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=sqlite3*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-sqlite3.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A SQLite3 storage driver using [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3). + +### Table of Contents +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures +```go +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() *sql.DB +``` +### Installation +SQLite3 is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: +```bash +go mod init github.com// +``` +And then install the sqlite3 implementation: +```bash +go get github.com/gofiber/storage/sqlite3 +``` + +### Examples +Import the storage package. +```go +import "github.com/gofiber/storage/sqlite3" +``` + +You can use the following possibilities to create a storage: +```go +// Initialize default config +store := sqlite3.New() + +// Initialize custom config +store := sqlite3.New(sqlite3.Config{ + Database: "./fiber.sqlite3", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, + MaxOpenConns: 100, + MaxIdleConns: 100, + ConnMaxLifetime: 1 * time.Second, +}) +``` + +### Config +```go +type Config struct { + // Database name + // + // Optional. Default is "fiber" + Database string + + // Table name + // + // Optional. Default is "fiber_storage" + Table string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration + + // ////////////////////////////////// + // Adaptor related config options // + // ////////////////////////////////// + + // MaxIdleConns sets the maximum number of connections in the idle connection pool. + // + // Optional. Default is 100. + MaxIdleConns int + + // MaxOpenConns sets the maximum number of open connections to the database. + // + // Optional. Default is 100. + MaxOpenConns int + + // ConnMaxLifetime sets the maximum amount of time a connection may be reused. + // + // Optional. Default is 1 second. + ConnMaxLifetime time.Duration +} +``` + +### Default Config +```go +var ConfigDefault = Config{ + Database: "./fiber.sqlite3", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, + MaxOpenConns: 100, + MaxIdleConns: 100, + ConnMaxLifetime: 1 * time.Second, +} +``` diff --git a/storage_versioned_sidebars/version-badger_v1.x.x-sidebars.json b/storage_versioned_sidebars/version-badger_v1.x.x-sidebars.json new file mode 100644 index 00000000000..caea0c03ba6 --- /dev/null +++ b/storage_versioned_sidebars/version-badger_v1.x.x-sidebars.json @@ -0,0 +1,8 @@ +{ + "tutorialSidebar": [ + { + "type": "autogenerated", + "dirName": "." + } + ] +} diff --git a/storage_versions.json b/storage_versions.json index 693d1389c44..5877774cef5 100644 --- a/storage_versions.json +++ b/storage_versions.json @@ -1,4 +1,5 @@ [ + "badger_v1.x.x", "couchbase_v1.x.x", "bbolt_v1.x.x", "memcache_v1.x.x",