-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
62 lines (56 loc) · 1.81 KB
/
main.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
package main
import (
"flag"
"log"
"runtime"
"runtime/debug"
"github.com/maxzerbini/dingo/explorer"
"github.com/maxzerbini/dingo/generators"
"github.com/maxzerbini/dingo/model"
"github.com/maxzerbini/dingo/producers"
)
var configPath string = "./config.json"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
debug.SetGCPercent(300)
flag.StringVar(&configPath, "conf", "./config.json", "path of the file config.json")
}
// Start the code generator
func main() {
flag.Parse()
log.Printf("DinGo Code Generator\r\n")
log.Printf("Processing configuration file %s\r\n", configPath)
config := model.LoadConfiguration(configPath)
exp := createExplorer(&config)
schema := exp.ExploreSchema(&config)
modelpkg := producers.ProduceModelPackage(&config, schema)
daopkg := producers.ProduceDaoPackage(&config, schema, modelpkg)
viewmodelpkg := producers.ProduceViewModelPackage(&config, schema)
bizpkg := producers.ProduceBizPackage(&config, modelpkg, daopkg, viewmodelpkg)
srvpkg := producers.ProduceServicePackage(&config, viewmodelpkg, bizpkg)
generators.GenerateModel(&config, modelpkg)
if !config.SkipDaoGeneration {
generators.GenerateDao(&config, daopkg)
if !config.SkipBizGeneration {
generators.GenerateViewModel(&config, viewmodelpkg)
generators.GenerateBiz(&config, bizpkg)
if !config.SkipServiceGeneration {
generators.GenerateService(&config, srvpkg)
generators.GenerateConfig(&config)
generators.GenerateMain(&config, srvpkg)
generators.GenerateCustomResources(&config)
}
}
}
log.Printf("Code generation done.\r\n")
}
func createExplorer(conf *model.Configuration) explorer.DatabaseExplorer {
switch conf.DatabaseType {
case "mysql":
return explorer.NewMySqlExplorer()
case "postgres":
return explorer.NewPostgreSqlExplorer()
default:
return explorer.NewMySqlExplorer()
}
}