add auto package name
This commit is contained in:
@@ -11,7 +11,6 @@ var TypeDicMp = map[string]string{
|
|||||||
"bigint": "int64",
|
"bigint": "int64",
|
||||||
"varchar": "string",
|
"varchar": "string",
|
||||||
"char": "string",
|
"char": "string",
|
||||||
"decimal(18,2)": "float64",
|
|
||||||
"date": "time.Time",
|
"date": "time.Time",
|
||||||
"datetime": "time.Time",
|
"datetime": "time.Time",
|
||||||
"bit(1)": "bool",
|
"bit(1)": "bool",
|
||||||
@@ -25,8 +24,9 @@ var TypeDicMp = map[string]string{
|
|||||||
|
|
||||||
//TypeMatchMp 模糊匹配类型
|
//TypeMatchMp 模糊匹配类型
|
||||||
var TypeMatchMp = map[string]string{
|
var TypeMatchMp = map[string]string{
|
||||||
`^(int)[(]\d+[)]`: "int",
|
`^(int)[(]\d+[)]`: "int",
|
||||||
`^(bigint)[(]\d+[)]`: "int64",
|
`^(bigint)[(]\d+[)]`: "int64",
|
||||||
`^(char)[(]\d+[)]`: "string",
|
`^(char)[(]\d+[)]`: "string",
|
||||||
`^(varchar)[(]\d+[)]`: "string",
|
`^(varchar)[(]\d+[)]`: "string",
|
||||||
|
`^(decimal)[(]\d+,\d+[)]`: "float64",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (e *GenElement) SetType(tp string) {
|
|||||||
|
|
||||||
//SetNotes 设置注释
|
//SetNotes 设置注释
|
||||||
func (e *GenElement) SetNotes(notes string) {
|
func (e *GenElement) SetNotes(notes string) {
|
||||||
e.Notes = strings.Replace(notes, "\n", "", -1)
|
e.Notes = strings.Replace(notes, "\n", ",", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddTag 添加一个tag标记
|
//AddTag 添加一个tag标记
|
||||||
@@ -66,7 +66,12 @@ func (e *GenElement) Generate() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var p PrintAtom
|
var p PrintAtom
|
||||||
p.Add(e.Name, e.Type, tag, "//", e.Notes)
|
if len(e.Notes) > 0 {
|
||||||
|
p.Add(e.Name, e.Type, tag, "// "+e.Notes)
|
||||||
|
} else {
|
||||||
|
p.Add(e.Name, e.Type, tag)
|
||||||
|
}
|
||||||
|
|
||||||
return p.Generate()[0]
|
return p.Generate()[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ func (s *GenStruct) SetNotes(notes string) {
|
|||||||
|
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
if len(v) > 0 {
|
if len(v) > 0 {
|
||||||
text = append(text, "//"+v)
|
text = append(text, "// "+v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.Notes = strings.Join(text, "\r\n")
|
s.Notes = strings.Join(text, "\r\n")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package gtools
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/xxjwxc/gormt/data/config"
|
"github.com/xxjwxc/gormt/data/config"
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ func Execute() {
|
|||||||
// fmt.Println(tt)
|
// fmt.Println(tt)
|
||||||
|
|
||||||
pkg := OnGetPackageInfo(orm, OnGetTables(orm))
|
pkg := OnGetPackageInfo(orm, OnGetTables(orm))
|
||||||
pkg.SetPackage("model")
|
pkg.SetPackage(getPkgName())
|
||||||
str := pkg.Generate()
|
str := pkg.Generate()
|
||||||
|
|
||||||
path := config.GetOutDir() + "/" + config.GetMysqlDbInfo().Database + ".go"
|
path := config.GetOutDir() + "/" + config.GetMysqlDbInfo().Database + ".go"
|
||||||
@@ -36,5 +37,29 @@ func Execute() {
|
|||||||
fmt.Println("formatting differs from gofmt's:")
|
fmt.Println("formatting differs from gofmt's:")
|
||||||
cmd, _ = exec.Command("gofmt", "-l", "-w", path).Output()
|
cmd, _ = exec.Command("gofmt", "-l", "-w", path).Output()
|
||||||
fmt.Println(string(cmd))
|
fmt.Println(string(cmd))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通过config outdir 配置获取报名
|
||||||
|
func getPkgName() string {
|
||||||
|
dir := config.GetOutDir()
|
||||||
|
dir = strings.Replace(dir, "\\", "/", -1)
|
||||||
|
if len(dir) > 0 {
|
||||||
|
if dir[len(dir)-1] == '/' {
|
||||||
|
dir = dir[:(len(dir) - 1)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var pkgName string
|
||||||
|
list := strings.Split(dir, "/")
|
||||||
|
if len(list) > 0 {
|
||||||
|
pkgName = list[len(list)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pkgName) == 0 || pkgName == "." {
|
||||||
|
list = strings.Split(tools.GetModelPath(), "/")
|
||||||
|
if len(list) > 0 {
|
||||||
|
pkgName = list[len(list)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkgName
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -6,7 +6,7 @@ require (
|
|||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/go-playground/locales v0.12.1 // indirect
|
github.com/go-playground/locales v0.12.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.16.0 // indirect
|
github.com/go-playground/universal-translator v0.16.0 // indirect
|
||||||
github.com/jinzhu/gorm v1.9.10 // indirect
|
github.com/jinzhu/gorm v1.9.10
|
||||||
github.com/leodido/go-urn v1.1.0 // indirect
|
github.com/leodido/go-urn v1.1.0 // indirect
|
||||||
github.com/spf13/cobra v0.0.5
|
github.com/spf13/cobra v0.0.5
|
||||||
github.com/xxjwxc/public v0.0.0-20190915135914-aefa9155c004
|
github.com/xxjwxc/public v0.0.0-20190915135914-aefa9155c004
|
||||||
|
|||||||
Reference in New Issue
Block a user