-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
96 lines (85 loc) · 2.36 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package entgqlplus
import "os"
type (
extensionOption = func(*extension)
database = string
)
const (
SQLite database = "sqlite"
MySQL database = "mysql"
PostgreSQL database = "postgres"
)
// WithMutation(b bool) enables entgqlplus to generate the Mutations.
// Default value is nil
func WithMutation(b bool) extensionOption {
return func(e *extension) {
e.config.Mutation = &b
}
}
// WithSubscription(b bool) enables entgqlplus to generate the Subscriptions.
// Works only if WithMutation(true) is enabled.
// Default value is nil
func WithSubscription(b bool) extensionOption {
return func(e *extension) {
e.config.Subscription = &b
}
}
// WithEchoServer(b bool) enables entgqlplus to generate the server, routes and the handlers.
// Default value is nil
func WithEchoServer(b bool) extensionOption {
return func(e *extension) {
e.config.Echo = &b
}
}
// WithJWTAuth(b bool) enables entgqlplus to generate the login route and the Protected middleware
// Works only if WithEcho(true) is enabled.
// Default value is nil
func WithJWTAuth(b bool) extensionOption {
return func(e *extension) {
e.config.JWT = &b
}
}
// WithDatabase(b Database) enables entgqlplus to generate the necessary code to connect to the database and migration.
// Default value is ""
func WithDatabase(d database, dbconfig ...string) extensionOption {
return func(e *extension) {
e.config.Database = d
if d == SQLite {
if len(dbconfig) == 1 {
e.config.DBConfig = dbconfig
} else {
e.config.DBConfig = []string{"db"}
}
} else if d == MySQL || d == PostgreSQL {
if len(dbconfig) == 3 {
e.config.DBConfig = dbconfig
} else {
e.config.DBConfig = []string{"user", "pass", "db"}
}
}
}
}
// WithConfigPath(p string) enables entgqlplus locate the gqlgen.yml config file.
// Default value is With WithConfigPath("../gqlgen.yml").
func WithConfigPath(p string) extensionOption {
return func(e *extension) {
_, err := os.Stat(p)
catch(err)
e.config.GqlGenPath = p
}
}
// WithFileUpload(b bool) adds upload mutation.
// this only works if WithMutation(true) is enabled.
// Default is nil
func WithFileUpload(b bool) extensionOption {
return func(e *extension) {
e.config.FileUpload = &b
}
}
// WithPrivacy(b bool) adds upload mutation.
// Default is nil
func WithPrivacy(b bool) extensionOption {
return func(e *extension) {
e.config.Privacy = &b
}
}