1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
kstruct.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2024-05-08 09:51 . 1
package xconsole
import (
"flag"
"fmt"
"gitee.com/xiaoyutab/xgotool/xstring"
)
// 根据传入的参数和类型生成结构体中的某一行
func kstruct(help bool) string {
if help {
return "根据传入的参数和类型生成结构体中的某一行"
}
field := ""
has_gorm := false
has_t := 1
types := ""
desc := ""
flag.StringVar(&field, "f", "demo", "格式化的字段描述")
flag.BoolVar(&has_gorm, "g", false, "是否输出gorm结构类型定义")
flag.StringVar(&types, "t", "string", "变量类型")
flag.IntVar(&has_t, "ot", 0, "兼容类型 0-不进行兼容 1-json.Number进行JSON兼容 2-sql.NullBool进行数据库兼容")
flag.StringVar(&desc, "desc", "", "字段描述信息")
flag.Parse()
fmt.Printf("\t// kstruct -t %s", types)
if field != "demo" {
fmt.Printf(" -f \"%s\"", field)
}
if has_gorm {
fmt.Printf(" -g")
}
if has_t > 0 {
fmt.Printf(" -ot %d", has_t)
}
fmt.Println()
if v, ok := sql_jianrong[types]; ok {
switch has_t {
case 1:
types = v.JSON
case 2:
types = v.DB
}
}
fmt.Println()
gfield := fmt.Sprintf("`json:\"%s\" form:\"%s\"", field, field)
if has_gorm {
gfield += fmt.Sprintf(" gorm:\"column:%s\"", field)
}
gfield += "`"
fmt.Printf("\t%s\t%s\t%s\t// %s\n\n", xstring.CamelCase(field), types, gfield, desc)
return ""
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.13

搜索帮助