Skip to content

Commit

Permalink
feat: 添加webtag主键隐藏开关
Browse files Browse the repository at this point in the history
  • Loading branch information
evildao committed May 16, 2020
1 parent 49f28e8 commit 447ad78
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ simple : false # 简单输出(默认gorm标签不输出)
is_out_sql : false # 是否输出 sql 原信息
is_out_func : true # 是否输出 快捷函数
is_web_tag : true # 是否打web标记(json标记前提条件)
is_web_tag_pk_hidden: true # web标记是否隐藏主键
is_foreign_key : true # 是否导出外键关联
is_gui : false # 是否ui模式显示
is_table_name : false # 是否直接生成表名函数
Expand Down
36 changes: 21 additions & 15 deletions data/config/MyIni.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import (

// Config custom config struct
type Config struct {
CfgBase `yaml:"base"`
MySQLInfo MysqlDbInfo `yaml:"mysql_info"`
OutDir string `yaml:"out_dir"`
URLTag string `yaml:"url_tag"` // url tag
Language string `yaml:"language"` // language
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
Simple bool `yaml:"simple"`
IsWEBTag bool `yaml:"is_web_tag"`
SingularTable bool `yaml:"singular_table"`
IsForeignKey bool `yaml:"is_foreign_key"`
IsOutSQL bool `yaml:"is_out_sql"`
IsOutFunc bool `yaml:"is_out_func"`
IsGUI bool `yaml:"is_gui"` //
IsTableName bool `yaml:"is_table_name"`
OutFileName string `yaml:"-"`
CfgBase `yaml:"base"`
MySQLInfo MysqlDbInfo `yaml:"mysql_info"`
OutDir string `yaml:"out_dir"`
URLTag string `yaml:"url_tag"` // url tag
Language string `yaml:"language"` // language
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
Simple bool `yaml:"simple"`
IsWEBTag bool `yaml:"is_web_tag"`
IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键
SingularTable bool `yaml:"singular_table"`
IsForeignKey bool `yaml:"is_foreign_key"`
IsOutSQL bool `yaml:"is_out_sql"`
IsOutFunc bool `yaml:"is_out_func"`
IsGUI bool `yaml:"is_gui"` //
IsTableName bool `yaml:"is_table_name"`
OutFileName string `yaml:"-"`
}

// MysqlDbInfo mysql database information. mysql 数据库信息
Expand Down Expand Up @@ -94,6 +95,11 @@ func GetIsWEBTag() bool {
return _map.IsWEBTag
}

// GetIsWebTagPkHidden web tag是否隐藏主键
func GetIsWebTagPkHidden() bool {
return _map.IsWebTagPkHidden
}

// GetIsForeignKey if is foreign key
func GetIsForeignKey() bool {
return _map.IsForeignKey
Expand Down
4 changes: 3 additions & 1 deletion data/view/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)

for _, v := range cols {
var tmp genstruct.GenElement
var isPK bool
if strings.EqualFold(v.Type, "gorm.Model") { // gorm model
tmp.SetType(v.Type) //
} else {
Expand All @@ -86,6 +87,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
// case ColumnsKeyDefault:
case ColumnsKeyPrimary: // primary key.主键
tmp.AddTag(_tagGorm, "primary_key")
isPK = true
case ColumnsKeyUnique: // unique key.唯一索引
tmp.AddTag(_tagGorm, "unique")
case ColumnsKeyIndex: // index key.复合索引
Expand All @@ -108,7 +110,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)

// json tag
if config.GetIsWEBTag() {
if strings.EqualFold(v.Name, "id") {
if isPK && config.GetIsWebTagPkHidden() {
tmp.AddTag(_tagJSON, "-")
} else {
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
Expand Down

0 comments on commit 447ad78

Please sign in to comment.