Skip to content

Commit 92da8e1

Browse files
committed
Revert DisableStartupCheck changes for select drivers
1 parent 9b205cb commit 92da8e1

File tree

16 files changed

+209
-102
lines changed

16 files changed

+209
-102
lines changed

memcache/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ type Config struct {
7373
//
7474
// Optional. Default is false
7575
Reset bool
76+
77+
// DisableStartupCheck skips the initial connection validation during New.
78+
//
79+
// Optional. Default is false
80+
DisableStartupCheck bool
7681
}
7782
```
7883

7984
### Default Config
8085
```go
8186
var ConfigDefault = Config{
8287
Servers: "127.0.0.1:11211",
88+
DisableStartupCheck: false,
8389
}
8490
```

memcache/config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ type Config struct {
1515
// Optional. Default is false
1616
Reset bool
1717

18+
// DisableStartupCheck skips the initial connection validation during New.
19+
//
20+
// Optional. Default is false
21+
DisableStartupCheck bool
22+
1823
// The socket read/write timeout.
1924
//
2025
// Optional. Default is 100 * time.Millisecond
@@ -31,9 +36,10 @@ type Config struct {
3136

3237
// ConfigDefault is the default config
3338
var ConfigDefault = Config{
34-
Servers: "127.0.0.1:11211",
35-
timeout: 100 * time.Millisecond,
36-
maxIdleConns: 2,
39+
Servers: "127.0.0.1:11211",
40+
timeout: 100 * time.Millisecond,
41+
maxIdleConns: 2,
42+
DisableStartupCheck: false,
3743
}
3844

3945
// Helper function to set default values

memcache/memcache.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ func New(config ...Config) *Storage {
3030
db.Timeout = cfg.timeout
3131
db.MaxIdleConns = cfg.maxIdleConns
3232

33-
// Ping database to ensure a connection has been made
34-
if err := db.Ping(); err != nil {
35-
panic(err)
36-
}
37-
38-
if cfg.Reset {
39-
if err := db.DeleteAll(); err != nil {
33+
if !cfg.DisableStartupCheck {
34+
// Ping database to ensure a connection has been made
35+
if err := db.Ping(); err != nil {
4036
panic(err)
4137
}
38+
39+
if cfg.Reset {
40+
if err := db.DeleteAll(); err != nil {
41+
panic(err)
42+
}
43+
}
4244
}
4345

4446
// Create storage

memcache/memcache_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ func Test_Memcache_Reset(t *testing.T) {
178178
require.Zero(t, len(result))
179179
}
180180

181+
func Test_Memcache_New_DisableStartupCheck(t *testing.T) {
182+
require.NotPanics(t, func() {
183+
store := New(Config{
184+
Servers: "127.0.0.1:11210",
185+
DisableStartupCheck: true,
186+
})
187+
require.NotNil(t, store)
188+
})
189+
}
190+
181191
func Test_Memcache_Close(t *testing.T) {
182192
testStore := newTestStore(t)
183193
require.Nil(t, testStore.Close())

mysql/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ type Config struct {
127127
// Optional. Default is false
128128
Reset bool
129129

130+
// DisableStartupCheck skips the initial connection validation during New.
131+
//
132+
// Optional. Default is false
133+
DisableStartupCheck bool
134+
130135
// Time before deleting expired keys
131136
//
132137
// Optional. Default is 10 * time.Second
@@ -143,6 +148,7 @@ var ConfigDefault = Config{
143148
Database: "fiber",
144149
Table: "fiber_storage",
145150
Reset: false,
151+
DisableStartupCheck: false,
146152
GCInterval: 10 * time.Second,
147153
}
148154
```

mysql/config.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ type Config struct {
5353
// Optional. Default is false
5454
Reset bool
5555

56+
// DisableStartupCheck skips the initial connection validation during New.
57+
//
58+
// Optional. Default is false
59+
DisableStartupCheck bool
60+
5661
// Time before deleting expired keys
5762
//
5863
// Optional. Default is 10 * time.Second
@@ -69,17 +74,18 @@ type Config struct {
6974

7075
// ConfigDefault is the default config
7176
var ConfigDefault = Config{
72-
Db: nil,
73-
ConnectionURI: "",
74-
Host: "127.0.0.1",
75-
Port: 3306,
76-
Database: "fiber",
77-
Table: "fiber_storage",
78-
Reset: false,
79-
GCInterval: 10 * time.Second,
80-
maxOpenConns: 100,
81-
maxIdleConns: 100,
82-
connMaxLifetime: 1 * time.Second,
77+
Db: nil,
78+
ConnectionURI: "",
79+
Host: "127.0.0.1",
80+
Port: 3306,
81+
Database: "fiber",
82+
Table: "fiber_storage",
83+
Reset: false,
84+
DisableStartupCheck: false,
85+
GCInterval: 10 * time.Second,
86+
maxOpenConns: 100,
87+
maxIdleConns: 100,
88+
connMaxLifetime: 1 * time.Second,
8389
}
8490

8591
func (c Config) dsn() string {

mysql/mysql.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,28 @@ func New(config ...Config) *Storage {
6363
db.SetConnMaxLifetime(cfg.connMaxLifetime)
6464
}
6565

66-
// Ping database to ensure a connection has been made
67-
if err := db.Ping(); err != nil {
68-
panic(err)
69-
}
70-
71-
// Drop table if Clear set to true
72-
if cfg.Reset {
73-
query := fmt.Sprintf(dropQuery, cfg.Table)
74-
if _, err = db.Exec(query); err != nil {
75-
_ = db.Close()
66+
if !cfg.DisableStartupCheck {
67+
// Ping database to ensure a connection has been made
68+
if err := db.Ping(); err != nil {
7669
panic(err)
7770
}
78-
}
7971

80-
// Init database queries
81-
for _, query := range initQuery {
82-
query = fmt.Sprintf(query, cfg.Table)
83-
if _, err := db.Exec(query); err != nil {
84-
_ = db.Close()
85-
panic(err)
72+
// Drop table if Clear set to true
73+
if cfg.Reset {
74+
query := fmt.Sprintf(dropQuery, cfg.Table)
75+
if _, err = db.Exec(query); err != nil {
76+
_ = db.Close()
77+
panic(err)
78+
}
79+
}
80+
81+
// Init database queries
82+
for _, query := range initQuery {
83+
query = fmt.Sprintf(query, cfg.Table)
84+
if _, err := db.Exec(query); err != nil {
85+
_ = db.Close()
86+
panic(err)
87+
}
8688
}
8789
}
8890

@@ -98,7 +100,9 @@ func New(config ...Config) *Storage {
98100
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= ? AND e != 0", cfg.Table),
99101
}
100102

101-
store.checkSchema(cfg.Table)
103+
if !cfg.DisableStartupCheck {
104+
store.checkSchema(cfg.Table)
105+
}
102106

103107
// Start garbage collector
104108
go store.gcTicker()

mysql/mysql_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ func Test_MYSQL_New(t *testing.T) {
108108
defer newConfigStore.Close()
109109
}
110110

111+
func Test_MYSQL_New_DisableStartupCheck(t *testing.T) {
112+
require.NotPanics(t, func() {
113+
store := New(Config{
114+
Host: "127.0.0.1",
115+
Port: 3308,
116+
DisableStartupCheck: true,
117+
})
118+
require.NotNil(t, store)
119+
defer store.Close()
120+
})
121+
}
122+
111123
func Test_MYSQL_GC(t *testing.T) {
112124
testVal := []byte("doe")
113125

postgres/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ type Config struct {
117117
// Optional. Default is false
118118
Reset bool
119119

120+
// DisableStartupCheck skips the initial connection validation during New.
121+
//
122+
// Optional. Default is false
123+
DisableStartupCheck bool
124+
120125
// Time before deleting expired keys
121126
//
122127
// Optional. Default is 10 * time.Second
@@ -135,6 +140,7 @@ var ConfigDefault = Config{
135140
Table: "fiber_storage",
136141
SSLMode: "disable",
137142
Reset: false,
143+
DisableStartupCheck: false,
138144
GCInterval: 10 * time.Second,
139145
}
140146
```

postgres/config.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ type Config struct {
6161
// Optional. Default is false
6262
Reset bool
6363

64+
// DisableStartupCheck skips the initial connection validation during New.
65+
//
66+
// Optional. Default is false
67+
DisableStartupCheck bool
68+
6469
// Time before deleting expired keys
6570
//
6671
// Optional. Default is 10 * time.Second
@@ -69,14 +74,15 @@ type Config struct {
6974

7075
// ConfigDefault is the default config
7176
var ConfigDefault = Config{
72-
ConnectionURI: "",
73-
Host: "127.0.0.1",
74-
Port: 5432,
75-
Database: "fiber",
76-
Table: "fiber_storage",
77-
SSLMode: "disable",
78-
Reset: false,
79-
GCInterval: 10 * time.Second,
77+
ConnectionURI: "",
78+
Host: "127.0.0.1",
79+
Port: 5432,
80+
Database: "fiber",
81+
Table: "fiber_storage",
82+
SSLMode: "disable",
83+
Reset: false,
84+
DisableStartupCheck: false,
85+
GCInterval: 10 * time.Second,
8086
}
8187

8288
func (c *Config) getDSN() string {

0 commit comments

Comments
 (0)