-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
55 lines (46 loc) · 1.12 KB
/
option.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
package daoongorm
type Option interface {
Apply(*DaoBase)
}
type OptionFunc func(daoBase *DaoBase)
func (of OptionFunc) Apply(daoBase *DaoBase) {
of(daoBase)
}
func OptionSetUseCache(useCache bool) Option {
return OptionFunc(func(daoBase *DaoBase) {
daoBase.useCache = useCache
})
}
// 设置缓存组件
func OptionSetCacheUtil(cacheUtil CacheInterface) Option {
return OptionFunc(func(daoBase *DaoBase) {
daoBase.cacheUtil = cacheUtil
})
}
func OptionSetCacheExpireTS(expireTS int) Option {
return OptionFunc(func(daoBase *DaoBase) {
daoBase.cacheExpireTS = expireTS
})
}
// 记录不存在是否也缓存
func OptionNewForceCache(newForceCache bool) Option {
return OptionFunc(func(daoBase *DaoBase) {
daoBase.newForceCache = newForceCache
})
}
func OptionSetFieldNameCreatedAt(fieldName string) Option {
return OptionFunc(func(daoBase *DaoBase) {
if fieldName == "" {
return
}
daoBase.fieldNameCreatedAt = fieldName
})
}
func OptionSetFieldNameUpdatedAt(fieldName string) Option {
return OptionFunc(func(daoBase *DaoBase) {
if fieldName == "" {
return
}
daoBase.fieldNameUpdatedAt = fieldName
})
}