-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (55 loc) · 2.03 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
63
64
65
66
package main
import (
"flag"
"fmt"
"github.com/dextercai/db-doc-gen/database"
"github.com/dextercai/db-doc-gen/define"
"github.com/dextercai/db-doc-gen/doc"
"github.com/dextercai/db-doc-gen/model"
"github.com/dextercai/db-doc-gen/util"
"os"
"path"
)
var dbConfig model.DbConfig
func main() {
fmt.Printf("github.com/dextercai/db-doc-gen (%s)\n", define.VERSION)
dbConfig = model.DbConfig{
DbType: flag.String("db-type", "mysql", "数据库类型:mysql"),
DocType: flag.String("doc-type", "online", "文档生成类型:online、offline"),
DocServe: flag.String("doc-serve", ":8080", "在线文档服务地址"),
Host: flag.String("host", "127.0.0.1", "数据库地址"),
Port: flag.Int("port", 3306, "数据库端口"),
User: flag.String("username", "admin", "数据库用户名"),
Password: flag.String("password", "123456", "数据库密码"),
Database: flag.String("database", "test", "数据库名"),
}
flag.Parse()
// 数据库文档生成配置
fmt.Printf("解析到配置信息: \n")
fmt.Printf("%s\t%s\n", "数据库类型", *dbConfig.DbType)
fmt.Printf("%s\t%s\n", "文档生成类型", *dbConfig.DocType)
fmt.Printf("%s\t%s\n", "文档服务地址", *dbConfig.DocServe)
fmt.Printf("%s\t%s\n", "数据库地址", *dbConfig.Host)
fmt.Printf("%s\t%d\n", "数据库端口", *dbConfig.Port)
fmt.Printf("%s\t%s\n", "数据库用户名", *dbConfig.User)
fmt.Printf("%s\t%s\n", "数据库密码", *dbConfig.Password)
fmt.Printf("%s\t%s\n", "数据库名", *dbConfig.Database)
db, err := database.InitDb(&dbConfig)
if err != nil {
panic(err)
}
dbInfo := db.GetDbInfo()
dbInfo.DbName = *dbConfig.Database
tables := db.GetTableInfo()
var docPath string
dir, _ := os.Getwd()
if *dbConfig.DocType == "online" {
docPath = path.Join(dir, "dist", dbInfo.DbName, "www")
util.CreateDir(docPath)
doc.CreateOnlineDoc(docPath, dbInfo, tables, *dbConfig.DocServe)
} else {
docPath = path.Join(dir, "dist", dbInfo.DbName)
util.CreateDir(docPath)
doc.CreateOfflineDoc(docPath, dbInfo, tables)
}
}