feat(ReverseEngine):给生成的文件添加表注释,当表注释不为空的时候会在import下面生成该注释信息
This commit is contained in:
@@ -6,5 +6,5 @@ type ContentGenerate interface {
|
||||
/*
|
||||
内容制造接口
|
||||
*/
|
||||
GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string
|
||||
GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, string string) string
|
||||
}
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ func dbReverse(path string, tableName string, dbName string, db *sql.DB) {
|
||||
}
|
||||
fms, hasTime := buildFieldMessage(cms) //创建字段名和类型的映射
|
||||
w := bufio.NewWriter(file) //进行文件的操作
|
||||
content := cg.GenerateFileContent(path, tableName, fms, hasTime, tagKey) //拼go文件
|
||||
content := cg.GenerateFileContent(path, tableName, fms, hasTime, tagKey, tableComment) //拼go文件
|
||||
_, err := w.WriteString(content)
|
||||
checkError(err, "写入出错了:")
|
||||
fErr, cErr := w.Flush(), file.Close()
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
|
||||
type FileContentSupport struct{}
|
||||
|
||||
func (FileContentSupport) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string {
|
||||
func (FileContentSupport) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, tableComment string) string {
|
||||
var build strings.Builder
|
||||
pName := splitLast(filePath, static.Splice)
|
||||
|
||||
writePackage(&build, pName) //写文件的引用包
|
||||
writeImportIfTime(&build, hasTime) //如果有time.Time类型的需要写入import
|
||||
writeTableComment(&build, tableComment) //写入表注释
|
||||
buildStructHead(&build, fileName) //写入结构体头
|
||||
|
||||
//对于没有字段的返回空定义的文件
|
||||
@@ -99,3 +100,10 @@ func splitLast(filePath string, split string) string {
|
||||
ss := strings.Split(filePath, split)
|
||||
return ss[len(ss)-1]
|
||||
}
|
||||
|
||||
func writeTableComment(builder *strings.Builder, s string) {
|
||||
if s != "" {
|
||||
builder.WriteString("//" + s)
|
||||
builder.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type FileContentSUpport2 struct{}
|
||||
|
||||
func (FileContentSUpport2) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string) string {
|
||||
func (FileContentSUpport2) GenerateFileContent(filePath string, fileName string, fms []entity.FieldMessage, hasTime bool, tagKey string, string string) string {
|
||||
fmt.Println("12321321")
|
||||
return " "
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user