代码拉取完成,页面将自动刷新
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)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。