/
tpl.go
58 lines (47 loc) · 1.04 KB
/
tpl.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
package parser
var tplModuleMain = `
package $$LowerModuleName$$
import (
"context"
"$$RootImportPath$$/internal/config"
"$$ModuleImportPath$$/api"
"$$ModuleImportPath$$/schema"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type $$ModuleName$$ struct {
DB *gorm.DB
}
func (a *$$ModuleName$$) AutoMigrate(ctx context.Context) error {
return a.DB.AutoMigrate()
}
func (a *$$ModuleName$$) Init(ctx context.Context) error {
if config.C.Storage.DB.AutoMigrate {
if err := a.AutoMigrate(ctx); err != nil {
return err
}
}
return nil
}
func (a *$$ModuleName$$) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
{{- if .FillRouterPrefix}}
v1 = v1.Group("$$LowerModuleName$$")
{{- end}}
return nil
}
func (a *$$ModuleName$$) Release(ctx context.Context) error {
return nil
}
`
var tplModuleWire = `
package $$LowerModuleName$$
import (
"$$ModuleImportPath$$/api"
"$$ModuleImportPath$$/biz"
"$$ModuleImportPath$$/dal"
"github.com/google/wire"
)
var Set = wire.NewSet(
wire.Struct(new($$ModuleName$$), "*"),
)
`