new
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/xxjwxc/public/tools"
|
||||
)
|
||||
|
||||
// 打印
|
||||
//Add 打印
|
||||
func (p *PrintAtom) Add(str ...interface{}) {
|
||||
var tmp string
|
||||
for _, v := range str {
|
||||
@@ -18,27 +18,27 @@ func (p *PrintAtom) Add(str ...interface{}) {
|
||||
p.lines = append(p.lines, tmp)
|
||||
}
|
||||
|
||||
// 打印
|
||||
//Generate 打印
|
||||
func (p *PrintAtom) Generate() []string {
|
||||
return p.lines
|
||||
}
|
||||
|
||||
//设置元素名字
|
||||
//SetName 设置元素名字
|
||||
func (e *GenElement) SetName(name string) {
|
||||
e.Name = name
|
||||
}
|
||||
|
||||
//设置元素类型
|
||||
//SetType 设置元素类型
|
||||
func (e *GenElement) SetType(tp string) {
|
||||
e.Type = tp
|
||||
}
|
||||
|
||||
//设置注释
|
||||
//SetNotes 设置注释
|
||||
func (e *GenElement) SetNotes(notes string) {
|
||||
e.Notes = notes
|
||||
}
|
||||
|
||||
//添加一个tag标记
|
||||
//AddTag 添加一个tag标记
|
||||
func (e *GenElement) AddTag(k string, v string) {
|
||||
if e.Tags == nil {
|
||||
e.Tags = make(map[string][]string)
|
||||
@@ -46,7 +46,7 @@ func (e *GenElement) AddTag(k string, v string) {
|
||||
e.Tags[k] = append(e.Tags[k], v)
|
||||
}
|
||||
|
||||
//获取结果数据
|
||||
//Generate 获取结果数据
|
||||
func (e *GenElement) Generate() string {
|
||||
tag := ""
|
||||
var tags []string
|
||||
@@ -66,32 +66,32 @@ func (e *GenElement) Generate() string {
|
||||
// struct
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//设置创建语句,备份使用
|
||||
//SetCreatTableStr 设置创建语句,备份使用
|
||||
func (s *GenStruct) SetCreatTableStr(sql string) {
|
||||
s.SqlBuildStr = sql
|
||||
s.SQLBuildStr = sql
|
||||
}
|
||||
|
||||
//获取结果数据
|
||||
//SetStructName 获取结果数据
|
||||
func (s *GenStruct) SetStructName(name string) {
|
||||
s.Name = name
|
||||
}
|
||||
|
||||
//设置注释
|
||||
func (e *GenStruct) SetNotes(notes string) {
|
||||
e.Notes = notes
|
||||
//SetNotes 设置注释
|
||||
func (s *GenStruct) SetNotes(notes string) {
|
||||
s.Notes = notes
|
||||
}
|
||||
|
||||
//添加一个/或多个元素
|
||||
//AddElement 添加一个/或多个元素
|
||||
func (s *GenStruct) AddElement(e ...GenElement) {
|
||||
s.Em = append(s.Em, e...)
|
||||
}
|
||||
|
||||
//获取结果数据
|
||||
//Generate 获取结果数据
|
||||
func (s *GenStruct) Generate() []string {
|
||||
var p PrintAtom
|
||||
if !config.GetSimple() {
|
||||
p.Add("/******sql******")
|
||||
p.Add(s.SqlBuildStr)
|
||||
p.Add(s.SQLBuildStr)
|
||||
p.Add("******sql******/")
|
||||
}
|
||||
p.Add("//", s.Notes)
|
||||
@@ -108,12 +108,12 @@ func (s *GenStruct) Generate() []string {
|
||||
// package
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//定义包名
|
||||
//SetPackage 定义包名
|
||||
func (p *GenPackage) SetPackage(pname string) {
|
||||
p.Name = pname
|
||||
}
|
||||
|
||||
//通过类型添加import
|
||||
//AddImport 通过类型添加import
|
||||
func (p *GenPackage) AddImport(imp string) {
|
||||
if p.Imports == nil {
|
||||
p.Imports = make(map[string]string)
|
||||
@@ -121,12 +121,12 @@ func (p *GenPackage) AddImport(imp string) {
|
||||
p.Imports[imp] = imp
|
||||
}
|
||||
|
||||
//添加一个结构体
|
||||
//AddStruct 添加一个结构体
|
||||
func (p *GenPackage) AddStruct(st GenStruct) {
|
||||
p.Structs = append(p.Structs, st)
|
||||
}
|
||||
|
||||
//获取结果数据
|
||||
//Generate 获取结果数据
|
||||
func (p *GenPackage) Generate() string {
|
||||
p.genimport() //补充 import
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package generate
|
||||
|
||||
//包类
|
||||
//IPackage 包类
|
||||
type IPackage interface {
|
||||
//定义包名
|
||||
SetPackage(string)
|
||||
@@ -12,7 +12,7 @@ type IPackage interface {
|
||||
Generate() string
|
||||
}
|
||||
|
||||
//结构体类
|
||||
//IStruct 结构体类
|
||||
type IStruct interface {
|
||||
//设置创建语句,备份使用
|
||||
SetCreatTableStr(string)
|
||||
@@ -30,7 +30,7 @@ type IStruct interface {
|
||||
Generate() []string
|
||||
}
|
||||
|
||||
//元素类
|
||||
//IElement 元素类
|
||||
type IElement interface {
|
||||
//设置元素名字
|
||||
SetName(string)
|
||||
@@ -51,7 +51,7 @@ type IElement interface {
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//元素类
|
||||
//GenElement 元素类
|
||||
type GenElement struct {
|
||||
Name string //元素名
|
||||
Type string //类型标记
|
||||
@@ -59,15 +59,15 @@ type GenElement struct {
|
||||
Tags map[string][]string //标记
|
||||
}
|
||||
|
||||
//结构体
|
||||
//GenStruct 结构体
|
||||
type GenStruct struct {
|
||||
SqlBuildStr string //创建sql语句
|
||||
SQLBuildStr string //创建sql语句
|
||||
Name string //名字
|
||||
Notes string //注释
|
||||
Em []GenElement //元素组合
|
||||
}
|
||||
|
||||
//包体
|
||||
//GenPackage 包体
|
||||
type GenPackage struct {
|
||||
Name string //名字
|
||||
Imports map[string]string //元素组合
|
||||
@@ -77,12 +77,14 @@ type GenPackage struct {
|
||||
//间隔
|
||||
var _interval = "\t"
|
||||
|
||||
//EImportsHead .
|
||||
var EImportsHead = map[string]string{
|
||||
"stirng": `"string"`,
|
||||
"time.Time": `"time"`,
|
||||
"gorm.Model": `"github.com/jinzhu/gorm"`,
|
||||
}
|
||||
|
||||
//PrintAtom .
|
||||
type PrintAtom struct {
|
||||
lines []string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user