mirror of
https://github.com/gofiber/storage.git
synced 2025-09-27 21:02:20 +08:00
🎄 xmas present
This commit is contained in:
@@ -4,45 +4,49 @@ import "time"
|
||||
|
||||
// Config defines the config for storage.
|
||||
type Config struct {
|
||||
// Time before deleting expired keys
|
||||
//
|
||||
// Default is 10 * time.Second
|
||||
GCInterval time.Duration
|
||||
|
||||
// DB host
|
||||
// Host name where the DB is hosted
|
||||
//
|
||||
// Optional. Default is "127.0.0.1"
|
||||
Host string
|
||||
|
||||
// DB port
|
||||
// Port where the DB is listening on
|
||||
//
|
||||
// Optional. Default is "5432"
|
||||
Port int64
|
||||
// Optional. Default is 5432
|
||||
Port int
|
||||
|
||||
// DB user name
|
||||
// Server username
|
||||
//
|
||||
// Optional. Default is ""
|
||||
Username string
|
||||
|
||||
// DB user password
|
||||
// Server password
|
||||
//
|
||||
// Optional. Default is ""
|
||||
Password string
|
||||
|
||||
// DB name
|
||||
// Database name
|
||||
//
|
||||
// Optional. Default is "fiber"
|
||||
Database string
|
||||
|
||||
// DB table name
|
||||
// Table name
|
||||
//
|
||||
// Optional. Default is "fiber"
|
||||
TableName string
|
||||
// Optional. Default is "fiber_storage"
|
||||
Table string
|
||||
|
||||
// Drop any existing table with the same name
|
||||
// Clear any existing keys in existing Table
|
||||
//
|
||||
// Optional. Default is false
|
||||
DropTable bool
|
||||
Clear bool
|
||||
|
||||
// Time before deleting expired keys
|
||||
//
|
||||
// Optional. Default is 10 * time.Second
|
||||
GCInterval time.Duration
|
||||
|
||||
////////////////////////////////////
|
||||
// Adaptor related config options //
|
||||
////////////////////////////////////
|
||||
|
||||
// Maximum wait for connection, in seconds. Zero or
|
||||
// n < 0 means wait indefinitely.
|
||||
@@ -79,13 +83,12 @@ type Config struct {
|
||||
|
||||
// ConfigDefault is the default config
|
||||
var ConfigDefault = Config{
|
||||
GCInterval: 10 * time.Second,
|
||||
Host: "127.0.0.1",
|
||||
Port: 5432,
|
||||
Database: "fiber",
|
||||
TableName: "fiber",
|
||||
DropTable: false,
|
||||
timeout: 30 * time.Second,
|
||||
Table: "fiber_storage",
|
||||
Clear: false,
|
||||
GCInterval: 10 * time.Second,
|
||||
maxOpenConns: 100,
|
||||
maxIdleConns: 100,
|
||||
connMaxLifetime: 1 * time.Second,
|
||||
@@ -102,35 +105,20 @@ func configDefault(config ...Config) Config {
|
||||
cfg := config[0]
|
||||
|
||||
// Set default values
|
||||
if int(cfg.GCInterval) == 0 {
|
||||
cfg.GCInterval = ConfigDefault.GCInterval
|
||||
}
|
||||
if cfg.Host == "" {
|
||||
cfg.Host = ConfigDefault.Host
|
||||
}
|
||||
if cfg.Port == 0 {
|
||||
if cfg.Port <= 0 {
|
||||
cfg.Port = ConfigDefault.Port
|
||||
}
|
||||
if cfg.Host == "" {
|
||||
cfg.Host = ConfigDefault.Host
|
||||
}
|
||||
if cfg.Database == "" {
|
||||
cfg.Database = ConfigDefault.Database
|
||||
}
|
||||
if cfg.TableName == "" {
|
||||
cfg.TableName = ConfigDefault.TableName
|
||||
if cfg.Table == "" {
|
||||
cfg.Table = ConfigDefault.Table
|
||||
}
|
||||
if int(cfg.GCInterval) == 0 {
|
||||
cfg.GCInterval = ConfigDefault.GCInterval
|
||||
}
|
||||
// if int(cfg.Timeout) == 0 {
|
||||
// cfg.Timeout = ConfigDefault.Timeout
|
||||
// }
|
||||
// if cfg.MaxOpenConns == 0 {
|
||||
// cfg.MaxOpenConns = ConfigDefault.MaxOpenConns
|
||||
// }
|
||||
// if cfg.MaxIdleConns == 0 {
|
||||
// cfg.MaxIdleConns = ConfigDefault.MaxIdleConns
|
||||
// }
|
||||
// if int(cfg.ConnMaxLifetime) == 0 {
|
||||
// cfg.ConnMaxLifetime = ConfigDefault.ConnMaxLifetime
|
||||
// }
|
||||
return cfg
|
||||
}
|
||||
|
Reference in New Issue
Block a user