add log & fix gui

添加文档并且更新gui
This commit is contained in:
谢小军
2020-01-22 11:23:53 +08:00
parent 40f837aecf
commit 169edf0f50
8 changed files with 63 additions and 32 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -12,6 +12,12 @@
### big Camel-Case Name Rule ### big Camel-Case Name Rule
### JSON tag ### JSON tag
## gui support
![show](/image/gormt/ui_en.gif)
## cmd support
![show](/image/gormt/out.gif) ![show](/image/gormt/out.gif)
-------- --------
@@ -19,12 +25,16 @@
## 1. Configure default configuration items through the current directory config.yml file ## 1. Configure default configuration items through the current directory config.yml file
``` ```
out_dir : "." # out dir out_dir : "." # out dir
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language : # language(English,中 文)
db_tag : gorm # DB tag(gorm,db)
singular_table : false # Table name plural (big Camel-Case):gorm.SingularTable singular_table : false # Table name plural (big Camel-Case):gorm.SingularTable
simple : false #simple output simple : false #simple output
is_out_sql : false # Whether to output sql is_out_sql : false # Whether to output sql
is_out_func : true # Whether to output function is_out_func : true # Whether to output function
is_json_tag : true # Whether to mark JSON or not is_url_tag : true # Whether to mark web or not
is_foreign_key : true # Whether to mark foreign key or not is_foreign_key : true # Whether to mark foreign key or not
is_gui : false # Whether to operate on gui
mysql_info : mysql_info :
host : "127.0.0.1" host : "127.0.0.1"
@@ -50,12 +60,14 @@ Flags:
-d, --database string 数据库名 -d, --database string 数据库名
-f, --foreign 是否导出外键关联 -f, --foreign 是否导出外键关联
-F, --fun 是否导出函数 -F, --fun 是否导出函数
-g, --gui 是否ui显示模式
-h, --help help for main -h, --help help for main
-H, --host string 数据库地址.(注意-H为大写) -H, --host string 数据库地址.(注意-H为大写)
-o, --outdir string 输出目录 -o, --outdir string 输出目录
-p, --password string 密码. -p, --password string 密码.
--port int 端口号 (default 3306) --port int 端口号 (default 3306)
-s, --singular 是否禁用表名复数 -s, --singular 是否禁用表名复数
-l, --url string url标签(json,url)
-u, --user string 用户名. -u, --user string 用户名.
``` ```

View File

@@ -9,6 +9,16 @@
#### mysql数据库转 struct 工具,可以将mysql数据库自动生成golang sturct结构带大驼峰命名规则。带json标签 #### mysql数据库转 struct 工具,可以将mysql数据库自动生成golang sturct结构带大驼峰命名规则。带json标签
## 交互界面模式
![show](/image/gormt/ui_cn.gif)
```
./gormt -g=true
```
## 命令行模式
![show](/image/gormt/out.gif) ![show](/image/gormt/out.gif)
@@ -18,19 +28,25 @@
## 1. 通过当前目录 config.yml 文件配置默认配置项 ## 1. 通过当前目录 config.yml 文件配置默认配置项
``` ```
out_dir : "." # 输出目录 base:
singular_table : false # 表名复数,是否大驼峰构建 参考:gorm.SingularTable is_dev : false
simple : false #简单输出 out_dir : ./model # 输出目录
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language : # 语言(English,中 文)
db_tag : gorm # 数据库标签(gorm,db)
singular_table : false # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable
simple : false # 简单输出(默认gorm标签不输出)
is_out_sql : false # 是否输出 sql 原信息 is_out_sql : false # 是否输出 sql 原信息
is_out_func : true # 是否输出 快捷函数 is_out_func : true # 是否输出 快捷函数
is_json_tag : false #是否打json标记 is_url_tag : true # 是否打web标记
is_foreign_key : true #是否导出外键关联 is_foreign_key : true # 是否导出外键关联
mysql_info : is_gui : false # 是否ui模式显示
host : "127.0.0.1" mysql_info:
host : 127.0.0.1
port : 3306 port : 3306
username : "root" username : root
password : "qwer" password : qwer
database : "oauth_db" database : oauth_db
``` ```
## 2. 可以使用命令行工具更新配置项 ## 2. 可以使用命令行工具更新配置项
@@ -56,12 +72,14 @@ Flags:
-d, --database string 数据库名 -d, --database string 数据库名
-f, --foreign 是否导出外键关联 -f, --foreign 是否导出外键关联
-F, --fun 是否导出函数 -F, --fun 是否导出函数
-g, --gui 是否ui显示模式
-h, --help help for main -h, --help help for main
-H, --host string 数据库地址.(注意-H为大写) -H, --host string 数据库地址.(注意-H为大写)
-o, --outdir string 输出目录 -o, --outdir string 输出目录
-p, --password string 密码. -p, --password string 密码.
--port int 端口号 (default 3306) --port int 端口号 (default 3306)
-s, --singular 是否禁用表名复数 -s, --singular 是否禁用表名复数
-l, --url string url标签(json,url)
-u, --user string 用户名. -u, --user string 用户名.
``` ```

View File

@@ -8,7 +8,7 @@ singular_table : false # 单表模式:true:禁用表名复数,false:采用表
simple : false # 简单输出(默认gorm标签不输出) simple : false # 简单输出(默认gorm标签不输出)
is_out_sql : false # 是否输出 sql 原信息 is_out_sql : false # 是否输出 sql 原信息
is_out_func : true # 是否输出 快捷函数 is_out_func : true # 是否输出 快捷函数
is_json_tag : true # 是否打json标记 is_url_tag : true # 是否打web标记
is_foreign_key : true # 是否导出外键关联 is_foreign_key : true # 是否导出外键关联
is_gui : false # 是否ui模式显示 is_gui : false # 是否ui模式显示
mysql_info: mysql_info:
@@ -16,4 +16,5 @@ mysql_info:
port : 3306 port : 3306
username : root username : root
password : qwer password : qwer
database : matrix database : oauth_db

View File

@@ -15,7 +15,7 @@ type Config struct {
Language string `yaml:"language"` // language Language string `yaml:"language"` // language
DbTag string `yaml:"db_tag"` // 数据库标签gormt,db DbTag string `yaml:"db_tag"` // 数据库标签gormt,db
Simple bool `yaml:"simple"` Simple bool `yaml:"simple"`
IsJSONTag bool `yaml:"is_json_tag"` IsWEBTag bool `yaml:"is_web_tag"`
SingularTable bool `yaml:"singular_table"` SingularTable bool `yaml:"singular_table"`
IsForeignKey bool `yaml:"is_foreign_key"` IsForeignKey bool `yaml:"is_foreign_key"`
IsOutSQL bool `yaml:"is_out_sql"` IsOutSQL bool `yaml:"is_out_sql"`
@@ -87,9 +87,9 @@ func SetSimple(b bool) {
_map.Simple = b _map.Simple = b
} }
// GetIsJSONTag json tag.json标记 // GetIsWEBTag json tag.json标记
func GetIsJSONTag() bool { func GetIsWEBTag() bool {
return _map.IsJSONTag return _map.IsWEBTag
} }
// GetIsForeignKey if is foreign key // GetIsForeignKey if is foreign key

View File

@@ -11,10 +11,10 @@ import (
// CfgBase base config struct // CfgBase base config struct
type CfgBase struct { type CfgBase struct {
SerialNumber string `json:"serial_number" yaml:"serial_number"` // version.版本号 // SerialNumber string `json:"serial_number" yaml:"serial_number"` // version.版本号
ServiceName string `json:"service_name" yaml:"service_name"` // service name .service名字 // ServiceName string `json:"service_name" yaml:"service_name"` // service name .service名字
ServiceDisplayname string `json:"service_displayname" yaml:"service_displayname"` // display name .显示名 // ServiceDisplayname string `json:"service_displayname" yaml:"service_displayname"` // display name .显示名
SerciceDesc string `json:"sercice_desc" yaml:"sercice_desc"` // sercice desc .service描述 // SerciceDesc string `json:"sercice_desc" yaml:"sercice_desc"` // sercice desc .service描述
IsDev bool `json:"is_dev" yaml:"is_dev"` // Is it a development version?是否是开发版本 IsDev bool `json:"is_dev" yaml:"is_dev"` // Is it a development version?是否是开发版本
} }
@@ -49,12 +49,12 @@ func InitFile(filename string) error {
} }
// GetServiceConfig Get service configuration information // GetServiceConfig Get service configuration information
func GetServiceConfig() (name, displayName, desc string) { // func GetServiceConfig() (name, displayName, desc string) {
name = _map.ServiceName // name = _map.ServiceName
displayName = _map.ServiceDisplayname // displayName = _map.ServiceDisplayname
desc = _map.SerciceDesc // desc = _map.SerciceDesc
return // return
} // }
// GetIsDev is is dev // GetIsDev is is dev
func GetIsDev() bool { func GetIsDev() bool {

View File

@@ -173,7 +173,7 @@ func enterSet(g *gocui.Gui, v *gocui.View) error {
maxX, _ := g.Size() maxX, _ := g.Size()
setlog(g, "") setlog(g, "")
// new form // new form
form = mycui.NewForm(g, "set_ui", "Sign Up", division(maxX, uiPart[0])+3, 3, 0, 0) form = mycui.NewForm(g, "set_ui", "Sign Up", division(maxX, uiPart[0])+2, 2, 0, 0)
// add input field // add input field
form.AddInputField("out_dir", SLocalize("out_dir"), formPart[0], formPart[1]).SetText(config.GetOutDir()). form.AddInputField("out_dir", SLocalize("out_dir"), formPart[0], formPart[1]).SetText(config.GetOutDir()).
@@ -314,7 +314,7 @@ func showStruct(g *gocui.Gui, v *gocui.View) error {
} }
} }
setlog(g, "") setlog(g, "\n\n\n")
for _, v := range out { for _, v := range out {
addlog(g, v) addlog(g, v)
} }

View File

@@ -105,7 +105,7 @@ func (m *_Model) genTableElement(cols []ColumusInfo) (el []genstruct.GenElement)
} }
// json tag // json tag
if config.GetIsJSONTag() { if config.GetIsWEBTag() {
if strings.EqualFold(v.Name, "id") { if strings.EqualFold(v.Name, "id") {
tmp.AddTag(_tagJSON, "-") tmp.AddTag(_tagJSON, "-")
} else { } else {
@@ -149,7 +149,7 @@ func (m *_Model) genForeignKey(col ColumusInfo) (fklist []genstruct.GenElement)
tmp.AddTag(_tagGorm, "foreignkey:"+v.ColumnName) tmp.AddTag(_tagGorm, "foreignkey:"+v.ColumnName)
// json tag // json tag
if config.GetIsJSONTag() { if config.GetIsWEBTag() {
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.TableName)+"_list") tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.TableName)+"_list")
} }