codegen

package
v1.2.16 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ColumnKeyPRI = "PRI" // 主键
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiCfg

type ApiCfg struct {
	CommonConfig
	TargetFilename string // 目标文件名
}

type ApiTplAnalysisRes

type ApiTplAnalysisRes struct {
	PackageName     string
	TplAnalysisList []TplAnalysisItem
}

type CommonConfig

type CommonConfig struct {
	PackageName       string                    // 包名
	TplDir            string                    // 模板目录
	RootDir           string                    // 生成文件的根目录
	LayerParentDirMap map[LayerName]string      // 各层级父目录,如果为空则使用默认规则
	LayerNameMap      map[LayerName]LayerName   // 各层级名称,如果为空则使用默认规则
	LayerPrefixMap    map[LayerName]LayerPrefix // 各层级前缀,如果为空则使用默认规则
	TplFuncMap        template.FuncMap          // 模板函数
}

type GenParams

type GenParams struct {
	ParamsList []GenParamsItem
}

type GenParamsItem

type GenParamsItem struct {
	Template       *template.Template
	TargetDir      string
	TargetFileName string
	ExtraParams    interface{}
}

type Generator

type Generator interface {
	AnalysisModuleTpl(db *gorm.DB, cfg *ModuleCfg) (*ModuleTplAnalysisRes, error)
	AnalysisApiTpl(cfg *ApiCfg) (*ApiTplAnalysisRes, error)
	Gen(params *GenParams) error
}

func NewGenerator

func NewGenerator() Generator

type LayerName

type LayerName string
const (
	LayerNameRouter     LayerName = "router"
	LayerNameController LayerName = "controller"
	LayerNameService    LayerName = "service"
	LayerNameDto        LayerName = "dto"
	LayerNameRequest    LayerName = "request"
	LayerNameResponse   LayerName = "response"
	LayerNameModel      LayerName = "model"
	LayerNameDao        LayerName = "dao"
	LayerNameCode       LayerName = "code"
	LayerNameObject     LayerName = "object"
)

type LayerPrefix

type LayerPrefix string

func (LayerPrefix) String

func (lp LayerPrefix) String() string

type ModelField

type ModelField struct {
	FieldName    string // 字段名称
	FieldType    string // 字段数据类型,如int、string
	ColumnName   string // 列名
	ColumnType   string // 列数据类型,如varchar(255)
	ColumnKey    string // 索引类型,如PRI(主键), UNI(唯一索引), MUL(非唯一索引)
	IsNullable   bool   // 是否允许为空
	DefaultValue string // 默认值
	Comment      string // 字段注释
}

type ModuleCfg

type ModuleCfg struct {
	CommonConfig
	TableName     string            `validate:"required"` // 表名
	ColumnTypeMap map[string]string // 表字段类型映射,入股为空则使用默认规则
}

type ModuleTplAnalysisItem

type ModuleTplAnalysisItem struct {
	TplAnalysisItem
	ModelFields []ModelField
}

type ModuleTplAnalysisRes

type ModuleTplAnalysisRes struct {
	PackageName     string
	TableName       string
	StructName      string
	TplAnalysisList []ModuleTplAnalysisItem
}

type TableList

type TableList []string

func (TableList) ToMap

func (l TableList) ToMap() map[string]struct{}

type TplAnalysisItem

type TplAnalysisItem struct {
	Template        *template.Template
	TplFilepath     string
	TplFilename     string
	OriginFilename  string
	TargetDir       string
	TargetFilename  string
	TargetFileExist bool
	OriginLayerName LayerName
	LayerName       LayerName
	LayerPrefix     LayerPrefix
}

Jump to

Keyboard shortcuts

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