/
options.go
80 lines (69 loc) · 1.8 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
package genhandler
type options struct {
ImplPath string
DescPath string
SwaggerDef map[string][]byte
SwaggerPath string
Impl bool
Force bool
ServiceSubDir bool
ApplyDefaultMiddlewares bool
ImplFileNameTmpl string
WithTests bool
}
type Option func(*options)
// SwaggerDef sets map of swagger.json per proto file
func SwaggerDef(swaggerDef map[string][]byte) Option {
return func(o *options) {
o.SwaggerDef = swaggerDef
}
}
// SwaggerPath sets path to store separate swagger files
func SwaggerPath(swaggerPath string) Option {
return func(o *options) {
o.SwaggerPath = swaggerPath
}
}
// ApplyDefaultMiddlewares toggles application of httpruntime/httpmw.DefaultChain to
// every generated handler.
func ApplyDefaultMiddlewares(apply bool) Option {
return func(o *options) {
o.ApplyDefaultMiddlewares = apply
}
}
// Impl sets Impl flag option (if true implementation will be generated)
func Impl(impl bool) Option {
return func(o *options) {
o.Impl = impl
}
}
// ImplPath sets path for implementation file
func ImplPath(path string) Option {
return func(o *options) {
o.ImplPath = path
}
}
// DescPath sets path for description and swagger file
func DescPath(path string) Option {
return func(o *options) {
o.DescPath = path
}
}
// Force sets force mode for generation implementation
func Force(force bool) Option {
return func(o *options) {
o.Force = force
}
}
// ServiceSubDir sets impl generation into sub directory
func ServiceSubDir(subDir bool) Option {
return func(o *options) {
o.ServiceSubDir = subDir
}
}
// WithTests sets if it needs for unit tests generation
func WithTests(needTests bool) Option {
return func(o *options) {
o.WithTests = needTests
}
}