actions

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenConfig = func(context *cli.Context) error {

	parseTemp, err := temp.ParseTemp(temp.Config, nil)
	if err != nil {
		return err
	}
	err = utils.GenFile("cli.yaml", parseTemp, false)
	if err != nil {
		return err
	}
	return nil
}
View Source
var GenController = func(context *cli.Context) error {
	db, _ := utils.GetDb()

	tables, err := db.Migrator().GetTables()
	if err != nil {
		return err
	}

	for _, table := range tables {

		args := struct {
			ControllerName string
			AppName        string
			CName          string
		}{
			utils.FirstUpper(table),
			viper.GetString("app_name"),
			table,
		}
		parseTemp, err := temp.ParseTemp(temp.Controller, args)
		if err != nil {
			fmt.Println(err)
			return err
		}
		err = utils.GenFile("controller/"+table+".go", parseTemp, false)
		if err != nil {
			fmt.Println(err)
			return err
		}

	}
	return nil
}

GenController 生成controller的action

View Source
var GenDatabase = func(context *cli.Context) error {

	pConfig, err := utils.GetProjectConfig()
	if err != nil {
		fmt.Println(err.Error())
		return err
	}
	if !pConfig.UseDb {
		err = errors.New("请开启配置文件中的use_db")
		return err
	}

	start := time.Now()
	dbconfig := viper.GetStringMapString("database")

	dsn := dbconfig["username"] + ":" + dbconfig["password"] + "@tcp(" + dbconfig["host"] + ":" + dbconfig["port"] + ")/" + dbconfig["dbname"] + "?charset=" + dbconfig["charset"] + "&parseTime=True&loc=Local"
	args := struct {
		Dsn string
	}{
		dsn,
	}
	parseTemp, err := temp.ParseTemp(temp.Db, args)
	if err != nil {
		return err
	}
	err = utils.GenFile("dal/db.go", parseTemp, false)
	if err != nil {
		return err
	}

	parseDiy, err := temp.ParseTemp(temp.Diy, nil)
	if err != nil {
		return err
	}
	err = utils.GenFile("dal/diy.go", parseDiy, false)
	if err != nil {
		return err
	}

	db, _ := utils.GetDb()
	g := gen.NewGenerator(gen.Config{
		OutPath:      "dal",
		Mode:         gen.WithDefaultQuery,
		ModelPkgPath: "dal/models",
		OutFile:      "gen.go",
	})
	g.UseDB(db)
	g.ApplyBasic(g.GenerateAllTable()...)
	g.Execute()
	fmt.Println("耗时:", time.Since(start))
	return nil
}

GenDatabase 生成项目录以及基础文件方法

View Source
var GenProject = func(context *cli.Context) error {
	start := time.Now()
	fmt.Println("开始生成目录结构...")

	GenDirs()

	genFiles := []fileInfo{
		{"main.go", temp.Index, false},
		{"go.mod", temp.Mod, false},
		{"router/base.go", temp.Router, true},
	}

	for _, file := range genFiles {
		args, err := utils.GetProjectConfig()
		parseTemp, err := temp.ParseTemp(file.Temp, args)
		if err != nil {
			return err
		}
		err = utils.GenFile(file.Name, parseTemp, file.IsOverlay)
		if err != nil {
			return err
		}
	}

	fmt.Println("生成目录结构结束!请执行go mod tidy")
	fmt.Println("耗时:", time.Since(start))
	return nil
}

GenProject 生成项目录以及基础文件方法

View Source
var GenServices = func(context *cli.Context) error {

	db, _ := utils.GetDb()
	tables, err := db.Migrator().GetTables()
	if err != nil {
		fmt.Println(err)
		return err
	}

	for _, table := range tables {

		err := os.MkdirAll("services/"+table, os.ModePerm)
		if err != nil {
			fmt.Println(err)
			return err
		}

		GenQueryFile(table)
		var cols []colInfo
		db.Raw("desc " + table).Scan(&cols)
	}
	return nil
}

GenServices ...

Functions

func GenDirs

func GenDirs()

GenDirs 生成项目目录

func GenQueryFile added in v0.2.7

func GenQueryFile(tableName string)

GenQueryFile 生成查询参数验证结构体

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL