actions

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: Apache-2.0 Imports: 10 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)
	if err != nil {
		return err
	}
	return nil
}
View Source
var GenDatabase = func(context *cli.Context) error {
	if _, err := os.Stat("cli.yaml"); err != nil {
		fmt.Println("请先执行gen-cli gen config")
		os.Exit(2)
	}

	viper.SetConfigName("cli")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println(err)
		return err
	}
	start := time.Now()
	dbconfig := viper.GetStringMapString("database")
	if _, ok := os.Stat("dal/db.go"); ok != nil {

		dsn := dbconfig["username"] + ":" + dbconfig["password"] + "@tcp(" + dbconfig["host"] + ":" + dbconfig["port"] + ")/" + dbconfig["dbname"] + "?charset=utf8&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)
		if err != nil {
			return err
		}
	} else {
		fmt.Println("db.go不会覆盖,如需修改请手动操作")
	}

	dsn := dbconfig["username"] + ":" + dbconfig["password"] + "@tcp(" + dbconfig["host"] + ":" + dbconfig["port"] + ")/" + dbconfig["dbname"] + "?charset=utf8&parseTime=True&loc=Local"
	db, _ := gorm.Open(mysql.Open(dsn))
	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 {

	if _, err := os.Stat("cli.yaml"); err != nil {
		fmt.Println("请先执行gen-cli gen config")
		os.Exit(2)
	}

	viper.SetConfigName("cli")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println(err)
		return err
	}

	start := time.Now()
	fmt.Println("开始生成目录结构...")

	GenDirs()

	args := struct {
		AppName string
	}{viper.GetString("appname")}
	parseTemp, err := temp.ParseTemp(temp.Index, args)
	if err != nil {
		return err
	}
	err = utils.GenFile("main.go", parseTemp)
	if err != nil {
		return err
	}

	args = struct {
		AppName string
	}{viper.GetString("appname")}
	parseTemp, err = temp.ParseTemp(temp.Mod, args)
	if err != nil {
		return err
	}
	err = utils.GenFile("go.mod", parseTemp)
	if err != nil {
		return err
	}

	parseTemp, err = temp.ParseTemp(temp.Router, nil)
	if err != nil {
		return err
	}
	err = utils.GenFile("router/base.go", parseTemp)
	if err != nil {
		return err
	}
	fmt.Println("生成目录结构结束!请执行go mod tidy")
	fmt.Println("耗时:", time.Since(start))
	return nil
}

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

Functions

func GenDirs

func GenDirs()

Types

This section is empty.

Jump to

Keyboard shortcuts

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