-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (67 loc) · 1.93 KB
/
Copy pathmain.go
File metadata and controls
73 lines (67 loc) · 1.93 KB
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
package main
import (
"flag"
"fmt"
"github.com/go-libraries/genModels"
"os"
"strings"
)
var (
modelPath string
driver string
dsn string
ignoreTable string
style string
packageName string
camel string
help bool
h bool
)
func init() {
currentPath, _ := os.Getwd()
flag.StringVar(&modelPath, "dir", currentPath, "a dir name save model file path, default is current path")
flag.StringVar(&driver, "driver", "mysql", "database driver,like `mysql` `mariadb`, default is mysql")
flag.StringVar(&dsn, "dsn", "", "connection info names dsn")
flag.StringVar(&ignoreTable, "ig_tables", "", "ignore table names, like [tableA,tableB]")
flag.StringVar(&style, "style", "default", "use orm style like `bee` `gorm`, default `default`")
flag.StringVar(&camel, "camel", "0", "json use camel 0 false 1 true")
flag.StringVar(&packageName, "package", "", "help")
flag.BoolVar(&help, "help", false, "this help")
flag.BoolVar(&h, "h", false, "this help")
}
func main() {
flag.Parse()
if h || help {
flag.Usage()
}
//dsn = "ceshiceshi:mgtj123456@tcp(rm-ly29w98y58jjy4s7x.mysql.rds.aliyuncs.com:3306)/mgtj_app_content?charset=utf8mb4"
//driver = "mysql"
//style = "grom"
//packageName = "content"
//modelPath = "d:\\work\\contents"
if dsn == "" {
flag.Usage()
}
if modelPath != "" {
_,e := os.Stat(modelPath)
if e != nil {
_ = os.Mkdir(modelPath, os.ModePerm)
}
}
flag.Usage = usage
genModels.GormFormat.JsonUseCamel = false
if camel == "0" {
genModels.GormFormat.JsonUseCamel = true
}
fmt.Println(genModels.GormFormat,camel, style)
driver := genModels.GetDriver(modelPath, driver, dsn, style, packageName)
if ignoreTable != "" {
ignoreTables := strings.Split(ignoreTable, ",")
driver.SetIgnoreTables(ignoreTables...)
}
driver.Run()
}
func usage() {
fmt.Println("Usage: model [-dir dirname] [-driver mysql] [-dsn username:password@tcp(host:port)/database]")
flag.PrintDefaults()
}