-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoption.go
47 lines (39 loc) · 966 Bytes
/
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
package egorm
import (
"gorm.io/gorm/schema"
"github.com/ego-component/egorm/manager"
)
// Option 可选项
type Option func(c *Container)
// WithDSN 设置dsn
func WithDSN(dsn string) Option {
return func(c *Container) {
c.config.DSN = dsn
}
}
// WithDialect 设置 dialect
func WithDialect(dialect string) Option {
return func(c *Container) {
c.config.Dialect = dialect
}
}
// WithDSNParser 设置自定义dsnParser
func WithDSNParser(parser manager.DSNParser) Option {
return func(c *Container) {
c.dsnParser = parser
}
}
func WithNamingStrategy(namingStrategy schema.Namer) Option {
return func(c *Container) {
c.config.namingStrategy = namingStrategy
}
}
// WithInterceptor 设置自定义拦截器
func WithInterceptor(is ...Interceptor) Option {
return func(c *Container) {
if c.config.interceptors == nil {
c.config.interceptors = make([]Interceptor, 0)
}
c.config.interceptors = append(c.config.interceptors, is...)
}
}