-
Notifications
You must be signed in to change notification settings - Fork 66
/
config.go
63 lines (51 loc) · 1.18 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package bbolt
import "time"
// 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 set to 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
}
// ConfigDefault is the default config
var ConfigDefault = Config{
Database: "fiber.db",
Bucket: "fiber_storage",
Timeout: 60 * time.Second,
ReadOnly: false,
Reset: false,
}
// Helper function to set default values
func configDefault(config ...Config) Config {
// Return default config if nothing provided
if len(config) < 1 {
return ConfigDefault
}
// Override default config
cfg := config[0]
// Set default values
if cfg.Database == "" {
cfg.Database = ConfigDefault.Database
}
if cfg.Bucket == "" {
cfg.Bucket = ConfigDefault.Bucket
}
return cfg
}