-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
76 lines (69 loc) · 1.7 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package entber
import "log"
func WithDB(config ...*DBConfig) option {
return func(e *extension) {
if len(config) == 0 {
e.data.DBConfig = new(DBConfig)
} else {
e.data.DBConfig = config[0]
}
if e.data.DBConfig.Path == "" {
e.data.DBConfig.Path = "db"
}
if e.data.DBConfig.Driver == "" {
e.data.DBConfig.Driver = SQLite
} else {
if !in(e.data.DBConfig.Driver, []string{MySQL, SQLite, PostgreSQL}) {
log.Fatalln("driver", e.data.DBConfig.Driver, "is not supported")
}
}
switch e.data.DBConfig.Driver {
case SQLite:
if e.data.DBConfig.Dsn == "" {
e.data.DBConfig.Dsn = "file:entber.sqlite?_fk=1&cache=shared"
}
case MySQL:
if e.data.DBConfig.Dsn == "" {
e.data.DBConfig.Dsn = "<user>:<pass>@tcp(<host>:<port>)/<database>?parseTime=True"
}
case PostgreSQL:
if e.data.DBConfig.Dsn == "" {
e.data.DBConfig.Dsn = "host=<host> port=<port> user=<user> dbname=<database> password=<pass>"
}
}
}
}
func WithFiber(config ...*FiberConfig) option {
return func(e *extension) {
if len(config) > 0 {
e.data.FiberConfig = config[0]
}
e.data.WithFiber = true
}
}
func WithEnt(config ...*EntConfig) option {
return func(e *extension) {
if len(config) == 0 {
e.data.EntConfig = &EntConfig{Input: true, Query: true, Edges: true, Base: false}
} else {
e.data.EntConfig = config[0]
}
}
}
func WithTS(config ...*TSConfig) option {
return func(e *extension) {
if len(config) == 0 {
e.data.TSConfig = new(TSConfig)
} else {
e.data.TSConfig = config[0]
}
if e.data.TSConfig.ApiPath == "" {
e.data.TSConfig.ApiPath = "ts/"
}
}
}
func WithAppConfig(config *AppConfig) option {
return func(e *extension) {
e.data.AppConfig = config
}
}