-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
42 lines (34 loc) · 840 Bytes
/
options.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
package postgres
import (
"time"
"gopkg.in/gorp.v2"
)
type Option interface {
apply(*Store)
}
type optionFunc func(store *Store)
func (f optionFunc) apply(store *Store) {
f(store)
}
// WithTableName sets the table name for the store.
func WithTableName(tableName string) Option {
return optionFunc(func(store *Store) {
if tableName != "" {
store.tableName = tableName
}
})
}
// WithSQLDialect sets the database for the store.
func WithSQLDialect(dialect gorp.PostgresDialect) Option {
return optionFunc(func(store *Store) {
store.db.Dialect = dialect
})
}
// WithGCTimeInterval sets the time interval for garbage collection.
func WithGCTimeInterval(interval int) Option {
return optionFunc(func(store *Store) {
if interval != 0 {
store.ticker = time.NewTicker(time.Second * time.Duration(interval))
}
})
}