diff --git a/memcache/README.md b/memcache/README.md index 4ec98e6a..ea9d2c6e 100644 --- a/memcache/README.md +++ b/memcache/README.md @@ -25,7 +25,7 @@ You can use the following possibilities to create a storage: store := memcache.New() // Initialize custom config -store := memcache.New(csrf.Config{ +store := memcache.New(memcache.Config{ Servers: "localhost:11211", Timeout: 100 * time.Millisecond, MaxIdleConns: 10, diff --git a/memory/README.md b/memory/README.md index b2f3514f..f08af3ce 100644 --- a/memory/README.md +++ b/memory/README.md @@ -1,9 +1,48 @@ -# In-memory +# Memory An in-memory storage driver. -### Creation +### Table of Contents +- [Signatures](#signatures) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) +### Signatures ```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, +} ``` diff --git a/memory/config.go b/memory/config.go index 8c296842..1bde4994 100644 --- a/memory/config.go +++ b/memory/config.go @@ -4,6 +4,9 @@ import "time" // Config defines the config for storage. type Config struct { + // Time before deleting expired keys + // + // Default is 10 * time.Second GCInterval time.Duration } diff --git a/mongodb/README.md b/mongodb/README.md index b7f1e398..a08474bd 100644 --- a/mongodb/README.md +++ b/mongodb/README.md @@ -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 -package main - -import "github.com/gofiber/storage/mongodb" - -func main() { - // Default storage - store := mongodb.New() - - // Custom storage - store := mongodb.New(mongodb.Config{ - URI: "mongodb://127.0.0.1:27017", - Database: "_database", - Collection: "_storage", - }) - - // Access DB connection - // for disconnet for example - if err := store.Close(); err != nil { - panic(err) - } -} - +func New(config ...Config) Storage +``` + +### 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{ + URI: "mongodb://127.0.0.1:27017", + Database: "fiber", + 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", +} ``` diff --git a/mongodb/config.go b/mongodb/config.go index 3408d2f1..9e8c22e0 100644 --- a/mongodb/config.go +++ b/mongodb/config.go @@ -14,8 +14,6 @@ import ( // Config defines the config for storage. type Config struct { - // Custom options - //https://docs.mongodb.com/manual/reference/connection-string/ URI string Database string @@ -55,8 +53,8 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ URI: "mongodb://127.0.0.1:27017", - Database: "_database", - Collection: "_storage", + Database: "fiber", + Collection: "fiber", } // Helper function to set default values diff --git a/postgres/README.md b/postgres/README.md index 6c0f2128..ec5674d9 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -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, +} +``` diff --git a/redis/README.md b/redis/README.md new file mode 100644 index 00000000..10c7a2c4 --- /dev/null +++ b/redis/README.md @@ -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", +} +``` diff --git a/sqlite3/README.md b/sqlite3/README.md index 8be264fc..c693885c 100644 --- a/sqlite3/README.md +++ b/sqlite3/README.md @@ -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, +} +```