1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.vscode
cmd
gormgen
pkg
README.MD
main.go
handlergen
mfmt
mysqlmd
pkg
vpn
.gitignore
LICENSE
README.md
go.mod
go.sum
克隆/下载
main.go 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 3个月前 . init project
package main
import (
"flag"
"log"
"os"
"strings"
"text/template"
"gitee.com/carlmax_my/console-core-go/cmd/gormgen/pkg"
// _ "github.com/joho/godotenv/autoload"
)
var (
input string
output string
pkgName string
structs []string
)
func init() {
pkg.LoadEnv() // auto load has path issue
flagStructs := flag.String("structs", "", "[Required] The name of schema structs to generate structs for, comma separated\n")
flagInput := flag.String("input", "", "[Required] The name of the input file dir\n")
flagOutput := flag.String("output", "", "The name of the output file dir\n")
flagPkg := flag.String("pkg", "", "The name of the package, default is the same with the input module\n")
flag.Parse()
if *flagStructs == "" || *flagInput == "" {
flag.Usage()
os.Exit(1)
}
structs = strings.Split(*flagStructs, ",")
input = *flagInput
if *flagOutput != "" {
output = *flagOutput
} else {
output = input
}
if *flagPkg != "" {
pkgName = *flagPkg
}
}
func main() {
mongo := os.Getenv("GO_GORM_MONGO")
log.Println("gormgen mongo:", mongo)
var template *template.Template
if mongo == "1" || mongo == "true" {
template = pkg.OutputTemplate_mongo
if strings.Contains(output, "/mysql/") {
output = strings.ReplaceAll(output, "/mysql/", "/mongo/")
}
} else {
template = pkg.OutputTemplate
}
gen := pkg.NewGenerator(input, output, pkgName, template)
p := pkg.NewParser(input)
if err := gen.ParserAST(p, structs).Generate().Format().Flush(); err != nil {
log.Fatalln(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.17

搜索帮助