-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.go
47 lines (41 loc) · 1004 Bytes
/
model.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 main
import (
"fmt"
"log"
"text/template"
"go-entity/writer"
)
func generateModel(tables []*Table) {
t := template.New("model_tmpl")
t, err := t.Parse(modelTmpl)
if err != nil {
log.Fatalln("template parse err:", err)
}
t2 := template.New("model_field_tmpl")
t2, err = t2.Parse(modelFieldTmpl)
if err != nil {
log.Fatalln("template parse err:", err)
}
for _, table := range tables {
w := writer.NewTemplateWriter(
t,
&writer.Config{
Terminal: Cfg.Terminal,
Path: fmt.Sprintf("%s/model/", Cfg.Output),
},
)
if err = w.Write(table, fmt.Sprintf("%s%s.go", _prefix, table.Name)); err != nil {
log.Fatalln("write occurred error:", err)
}
w = writer.NewTemplateWriter(
t2,
&writer.Config{
Terminal: Cfg.Terminal,
Path: fmt.Sprintf("%s/model/%s", Cfg.Output, table.PackageName),
},
)
if err = w.Write(table, fmt.Sprintf("%s%s.go", _prefix, table.Name)); err != nil {
log.Fatalln("write occurred error:", err)
}
}
}