mirror of
https://github.com/gofiber/storage.git
synced 2025-10-08 10:00:32 +08:00
✏ update configs
This commit is contained in:
@@ -25,7 +25,7 @@ You can use the following possibilities to create a storage:
|
|||||||
store := memcache.New()
|
store := memcache.New()
|
||||||
|
|
||||||
// Initialize custom config
|
// Initialize custom config
|
||||||
store := memcache.New(csrf.Config{
|
store := memcache.New(memcache.Config{
|
||||||
Servers: "localhost:11211",
|
Servers: "localhost:11211",
|
||||||
Timeout: 100 * time.Millisecond,
|
Timeout: 100 * time.Millisecond,
|
||||||
MaxIdleConns: 10,
|
MaxIdleConns: 10,
|
||||||
|
@@ -1,9 +1,48 @@
|
|||||||
# In-memory
|
# Memory
|
||||||
|
|
||||||
An in-memory storage driver.
|
An in-memory storage driver.
|
||||||
|
|
||||||
### Creation
|
### Table of Contents
|
||||||
|
- [Signatures](#signatures)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Config](#config)
|
||||||
|
- [Default Config](#default-config)
|
||||||
|
|
||||||
|
### Signatures
|
||||||
```go
|
```go
|
||||||
store := memory.New()
|
func New(config ...Config) Storage
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
@@ -4,6 +4,9 @@ import "time"
|
|||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Time before deleting expired keys
|
||||||
|
//
|
||||||
|
// Default is 10 * time.Second
|
||||||
GCInterval time.Duration
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,29 +1,82 @@
|
|||||||
# mongodb
|
# MongoDB
|
||||||
|
|
||||||
Storage uses MongoDB
|
A MongoDB storage driver using [mongodb/mongo-go-driver](https://github.com/mongodb/mongo-go-driver).
|
||||||
|
|
||||||
### Usage
|
### Table of Contents
|
||||||
|
- [Signatures](#signatures)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Config](#config)
|
||||||
|
- [Default Config](#default-config)
|
||||||
|
|
||||||
|
### Signatures
|
||||||
```go
|
```go
|
||||||
package main
|
func New(config ...Config) Storage
|
||||||
|
```
|
||||||
import "github.com/gofiber/storage/mongodb"
|
|
||||||
|
### Examples
|
||||||
func main() {
|
Import the storage package.
|
||||||
// Default storage
|
```go
|
||||||
store := mongodb.New()
|
import "github.com/gofiber/storage/mongodb"
|
||||||
|
```
|
||||||
// Custom storage
|
|
||||||
store := mongodb.New(mongodb.Config{
|
You can use the following possibilities to create a storage:
|
||||||
URI: "mongodb://127.0.0.1:27017",
|
```go
|
||||||
Database: "_database",
|
// Initialize default config
|
||||||
Collection: "_storage",
|
store := mongodb.New()
|
||||||
})
|
|
||||||
|
// Initialize custom config
|
||||||
// Access DB connection
|
store := mongodb.New(mongodb.Config{
|
||||||
// for disconnet for example
|
URI: "mongodb://127.0.0.1:27017",
|
||||||
if err := store.Close(); err != nil {
|
Database: "fiber",
|
||||||
panic(err)
|
Collection: "fiber",
|
||||||
}
|
})
|
||||||
}
|
```
|
||||||
|
|
||||||
|
### Config
|
||||||
|
```go
|
||||||
|
type Config struct {
|
||||||
|
//https://docs.mongodb.com/manual/reference/connection-string/
|
||||||
|
URI string
|
||||||
|
Database string
|
||||||
|
Collection string
|
||||||
|
|
||||||
|
// https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.2/mongo/options#ClientOptions
|
||||||
|
AppName string
|
||||||
|
Auth options.Credential
|
||||||
|
AutoEncryptionOptions *options.AutoEncryptionOptions
|
||||||
|
ConnectTimeout time.Duration
|
||||||
|
Compressors []string
|
||||||
|
Dialer options.ContextDialer
|
||||||
|
Direct bool
|
||||||
|
DisableOCSPEndpointCheck bool
|
||||||
|
HeartbeatInterval time.Duration
|
||||||
|
Hosts []string
|
||||||
|
LocalThreshold time.Duration
|
||||||
|
MaxConnIdleTime time.Duration
|
||||||
|
MaxPoolSize uint64
|
||||||
|
MinPoolSize uint64
|
||||||
|
PoolMonitor *event.PoolMonitor
|
||||||
|
Monitor *event.CommandMonitor
|
||||||
|
ReadConcern *readconcern.ReadConcern
|
||||||
|
ReadPreference *readpref.ReadPref
|
||||||
|
Registry *bsoncodec.Registry
|
||||||
|
ReplicaSet string
|
||||||
|
RetryReads bool
|
||||||
|
RetryWrites bool
|
||||||
|
ServerSelectionTimeout time.Duration
|
||||||
|
SocketTimeout time.Duration
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
WriteConcern *writeconcern.WriteConcern
|
||||||
|
ZlibLevel int
|
||||||
|
ZstdLevel int
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Default Config
|
||||||
|
```go
|
||||||
|
var ConfigDefault = Config{
|
||||||
|
URI: "mongodb://127.0.0.1:27017",
|
||||||
|
Database: "fiber",
|
||||||
|
Collection: "fiber",
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
@@ -14,8 +14,6 @@ import (
|
|||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Custom options
|
|
||||||
|
|
||||||
//https://docs.mongodb.com/manual/reference/connection-string/
|
//https://docs.mongodb.com/manual/reference/connection-string/
|
||||||
URI string
|
URI string
|
||||||
Database string
|
Database string
|
||||||
@@ -55,8 +53,8 @@ type Config struct {
|
|||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{
|
var ConfigDefault = Config{
|
||||||
URI: "mongodb://127.0.0.1:27017",
|
URI: "mongodb://127.0.0.1:27017",
|
||||||
Database: "_database",
|
Database: "fiber",
|
||||||
Collection: "_storage",
|
Collection: "fiber",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
|
@@ -1 +1,134 @@
|
|||||||
# postgres
|
# Postgres
|
||||||
|
|
||||||
|
A Postgres storage driver using [lib/pq](https://github.com/lib/pq).
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
- [Signatures](#signatures)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Config](#config)
|
||||||
|
- [Default Config](#default-config)
|
||||||
|
|
||||||
|
### Signatures
|
||||||
|
```go
|
||||||
|
func New(config ...Config) Storage
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
Import the storage package.
|
||||||
|
```go
|
||||||
|
import "github.com/gofiber/storage/postgres"
|
||||||
|
```
|
||||||
|
|
||||||
|
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{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
Host: "127.0.0.1",
|
||||||
|
Port: 5432,
|
||||||
|
Database: "fiber",
|
||||||
|
TableName: "fiber",
|
||||||
|
DropTable: false,
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
MaxOpenConns: 100,
|
||||||
|
MaxIdleConns: 100,
|
||||||
|
ConnMaxLifetime: 1 * time.Second,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config
|
||||||
|
```go
|
||||||
|
// Config defines the config for storage.
|
||||||
|
type Config struct {
|
||||||
|
// Time before deleting expired keys
|
||||||
|
//
|
||||||
|
// Default is 10 * time.Second
|
||||||
|
GCInterval time.Duration
|
||||||
|
|
||||||
|
// DB host
|
||||||
|
//
|
||||||
|
// Optional. Default is "127.0.0.1"
|
||||||
|
Host string
|
||||||
|
|
||||||
|
// DB port
|
||||||
|
//
|
||||||
|
// Optional. Default is "5432"
|
||||||
|
Port int64
|
||||||
|
|
||||||
|
// DB user name
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
Username string
|
||||||
|
|
||||||
|
// DB user password
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
Password string
|
||||||
|
|
||||||
|
// DB name
|
||||||
|
//
|
||||||
|
// Optional. Default is "fiber"
|
||||||
|
Database string
|
||||||
|
|
||||||
|
// DB table name
|
||||||
|
//
|
||||||
|
// Optional. Default is "fiber"
|
||||||
|
TableName string
|
||||||
|
|
||||||
|
// Drop any existing table with the same name
|
||||||
|
//
|
||||||
|
// Optional. Default is false
|
||||||
|
DropTable bool
|
||||||
|
|
||||||
|
// Maximum wait for connection, in seconds. Zero or
|
||||||
|
// n < 0 means wait indefinitely.
|
||||||
|
Timeout time.Duration
|
||||||
|
|
||||||
|
// The maximum number of connections in the idle connection pool.
|
||||||
|
//
|
||||||
|
// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
|
||||||
|
// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
|
||||||
|
//
|
||||||
|
// If n <= 0, no idle connections are retained.
|
||||||
|
//
|
||||||
|
// The default max idle connections is currently 2. This may change in
|
||||||
|
// a future release.
|
||||||
|
MaxIdleConns int
|
||||||
|
|
||||||
|
// The maximum number of open connections to the database.
|
||||||
|
//
|
||||||
|
// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
|
||||||
|
// MaxIdleConns, then MaxIdleConns will be reduced to match the new
|
||||||
|
// MaxOpenConns limit.
|
||||||
|
//
|
||||||
|
// If n <= 0, then there is no limit on the number of open connections.
|
||||||
|
// The default is 0 (unlimited).
|
||||||
|
MaxOpenConns int
|
||||||
|
|
||||||
|
// The maximum amount of time a connection may be reused.
|
||||||
|
//
|
||||||
|
// Expired connections may be closed lazily before reuse.
|
||||||
|
//
|
||||||
|
// If d <= 0, connections are reused forever.
|
||||||
|
ConnMaxLifetime time.Duration
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Default Config
|
||||||
|
```go
|
||||||
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
Host: "127.0.0.1",
|
||||||
|
Port: 5432,
|
||||||
|
Database: "fiber",
|
||||||
|
TableName: "fiber",
|
||||||
|
DropTable: false,
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
MaxOpenConns: 100,
|
||||||
|
MaxIdleConns: 100,
|
||||||
|
ConnMaxLifetime: 1 * time.Second,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
135
redis/README.md
Normal file
135
redis/README.md
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
# Redis
|
||||||
|
|
||||||
|
A Redis storage driver using [go-redis/redis](github.com/go-redis/redis).
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
- [Signatures](#signatures)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Config](#config)
|
||||||
|
- [Default Config](#default-config)
|
||||||
|
|
||||||
|
### Signatures
|
||||||
|
```go
|
||||||
|
func New(config ...Config) Storage
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
Import the storage package.
|
||||||
|
```go
|
||||||
|
import "github.com/gofiber/storage/redis"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use the following possibilities to create a storage:
|
||||||
|
```go
|
||||||
|
// Initialize default config
|
||||||
|
store := redis.New()
|
||||||
|
|
||||||
|
// Initialize custom config
|
||||||
|
store := redis.New(redis.Config{
|
||||||
|
Addr: "127.0.0.1:6379",
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config
|
||||||
|
```go
|
||||||
|
type Config struct {
|
||||||
|
// Custom options
|
||||||
|
|
||||||
|
// https://pkg.go.dev/github.com/go-redis/redis/v8#Options
|
||||||
|
|
||||||
|
// The network type, either tcp or unix.
|
||||||
|
// Default is tcp.
|
||||||
|
Network string
|
||||||
|
|
||||||
|
// host:port address.
|
||||||
|
Addr string
|
||||||
|
|
||||||
|
// Dialer creates new network connection and has priority over
|
||||||
|
// Network and Addr options.
|
||||||
|
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||||
|
|
||||||
|
// Hook that is called when new connection is established.
|
||||||
|
OnConnect func(ctx context.Context, cn *redis.Conn) error
|
||||||
|
|
||||||
|
// Use the specified Username to authenticate the current connection
|
||||||
|
// with one of the connections defined in the ACL list when connecting
|
||||||
|
// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
|
||||||
|
Username string
|
||||||
|
// Optional password. Must match the password specified in the
|
||||||
|
// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
|
||||||
|
// or the User Password when connecting to a Redis 6.0 instance, or greater,
|
||||||
|
// that is using the Redis ACL system.
|
||||||
|
Password string
|
||||||
|
|
||||||
|
// Database to be selected after connecting to the server.
|
||||||
|
DB int
|
||||||
|
|
||||||
|
// Maximum number of retries before giving up.
|
||||||
|
// Default is 3 retries.
|
||||||
|
MaxRetries int
|
||||||
|
|
||||||
|
// Minimum backoff between each retry.
|
||||||
|
// Default is 8 milliseconds; -1 disables backoff.
|
||||||
|
MinRetryBackoff time.Duration
|
||||||
|
|
||||||
|
// Maximum backoff between each retry.
|
||||||
|
// Default is 512 milliseconds; -1 disables backoff.
|
||||||
|
MaxRetryBackoff time.Duration
|
||||||
|
|
||||||
|
// Dial timeout for establishing new connections.
|
||||||
|
// Default is 5 seconds.
|
||||||
|
DialTimeout time.Duration
|
||||||
|
|
||||||
|
// Timeout for socket reads. If reached, commands will fail
|
||||||
|
// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
|
||||||
|
// Default is 3 seconds.
|
||||||
|
ReadTimeout time.Duration
|
||||||
|
|
||||||
|
// Timeout for socket writes. If reached, commands will fail
|
||||||
|
// with a timeout instead of blocking.
|
||||||
|
// Default is ReadTimeout.
|
||||||
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
|
// Maximum number of socket connections.
|
||||||
|
// Default is 10 connections per every CPU as reported by runtime.NumCPU.
|
||||||
|
PoolSize int
|
||||||
|
|
||||||
|
// Minimum number of idle connections which is useful when establishing
|
||||||
|
// new connection is slow.
|
||||||
|
MinIdleConns int
|
||||||
|
|
||||||
|
// Connection age at which client retires (closes) the connection.
|
||||||
|
// Default is to not close aged connections.
|
||||||
|
MaxConnAge time.Duration
|
||||||
|
|
||||||
|
// Amount of time client waits for connection if all connections
|
||||||
|
// are busy before returning an error.
|
||||||
|
// Default is ReadTimeout + 1 second.
|
||||||
|
PoolTimeout time.Duration
|
||||||
|
|
||||||
|
// Amount of time after which client closes idle connections.
|
||||||
|
// Should be less than server's timeout.
|
||||||
|
// Default is 5 minutes. -1 disables idle timeout check.
|
||||||
|
IdleTimeout time.Duration
|
||||||
|
|
||||||
|
// Frequency of idle checks made by idle connections reaper.
|
||||||
|
// Default is 1 minute. -1 disables idle connections reaper,
|
||||||
|
// but idle connections are still discarded by the client
|
||||||
|
// if IdleTimeout is set.
|
||||||
|
IdleCheckFrequency time.Duration
|
||||||
|
|
||||||
|
// TLS Config to use. When set TLS will be negotiated.
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
// Limiter interface used to implemented circuit breaker or rate limiter.
|
||||||
|
Limiter redis.Limiter
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Default Config
|
||||||
|
```go
|
||||||
|
var ConfigDefault = Config{
|
||||||
|
Addr: "127.0.0.1:6379",
|
||||||
|
}
|
||||||
|
```
|
@@ -1 +1,103 @@
|
|||||||
# sqlite3
|
# SQLite3
|
||||||
|
|
||||||
|
A SQLite3 storage driver using [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3).
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
- [Signatures](#signatures)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Config](#config)
|
||||||
|
- [Default Config](#default-config)
|
||||||
|
|
||||||
|
### Signatures
|
||||||
|
```go
|
||||||
|
func New(config ...Config) Storage
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
Database: "./fiber.sqlite3",
|
||||||
|
TableName: "fiber",
|
||||||
|
DropTable: false,
|
||||||
|
MaxOpenConns: 100,
|
||||||
|
MaxIdleConns: 100,
|
||||||
|
ConnMaxLifetime: 1 * time.Second,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config
|
||||||
|
```go
|
||||||
|
type Config struct {
|
||||||
|
// Time before deleting expired keys
|
||||||
|
//
|
||||||
|
// Default is 10 * time.Second
|
||||||
|
GCInterval time.Duration
|
||||||
|
|
||||||
|
// DB file path
|
||||||
|
//
|
||||||
|
// Default is "./fiber.sqlite3"
|
||||||
|
Database string
|
||||||
|
|
||||||
|
// DB table name
|
||||||
|
//
|
||||||
|
// Default is "fiber"
|
||||||
|
TableName string
|
||||||
|
|
||||||
|
// When set to true, this will Drop any existing table with the same name
|
||||||
|
DropTable bool
|
||||||
|
|
||||||
|
// The maximum number of connections in the idle connection pool.
|
||||||
|
//
|
||||||
|
// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
|
||||||
|
// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
|
||||||
|
//
|
||||||
|
// If n < 0, no idle connections are retained.
|
||||||
|
//
|
||||||
|
// The default is 100.
|
||||||
|
MaxIdleConns int
|
||||||
|
|
||||||
|
// The maximum number of open connections to the database.
|
||||||
|
//
|
||||||
|
// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
|
||||||
|
// MaxIdleConns, then MaxIdleConns will be reduced to match the new
|
||||||
|
// MaxOpenConns limit.
|
||||||
|
//
|
||||||
|
// If n < 0, then there is no limit on the number of open connections.
|
||||||
|
//
|
||||||
|
// The default is 100.
|
||||||
|
MaxOpenConns int
|
||||||
|
|
||||||
|
// The maximum amount of time a connection may be reused.
|
||||||
|
//
|
||||||
|
// Expired connections may be closed lazily before reuse.
|
||||||
|
//
|
||||||
|
// If d < 0, connections are reused forever.
|
||||||
|
//
|
||||||
|
// The default is 1 * time.Second
|
||||||
|
ConnMaxLifetime time.Duration
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Default Config
|
||||||
|
```go
|
||||||
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
Database: "./fiber.sqlite3",
|
||||||
|
TableName: "fiber",
|
||||||
|
DropTable: false,
|
||||||
|
MaxOpenConns: 100,
|
||||||
|
MaxIdleConns: 100,
|
||||||
|
ConnMaxLifetime: 1 * time.Second,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user