Documentation
¶
Index ¶
- func GenerateApiService(homeDir string, tableName string, schema []ColumnSchema, ...) (string, error)
- func GenerateGetByIdLogic(homeDir string, ...) (string, error)
- func GenerateGormModel(modelPkgName string, homeDir string, tableName string, columns []ColumnSchema, ...) (string, error)
- func GetCopyTemplate(homeDir string) ([]byte, error)
- func GetCreateTemplate(homeDir string) ([]byte, error)
- func GetDeleteTemplate(homeDir string) ([]byte, error)
- func GetGetByIdTemplate(homeDir string) ([]byte, error)
- func GetGetListTemplate(homeDir string) ([]byte, error)
- func GetGoZeroApiTemplate(homeDir string) ([]byte, error)
- func GetGormModelTemplate(homeDir string) ([]byte, error)
- func GetTypeMappings(homeDir string) (map[string]TypeMapping, error)
- func GetUpdateTemplate(homeDir string) ([]byte, error)
- func ToCamelCase(s string) string
- func ToLowerCamelCase(s string) string
- func ToSnakeCase(str string) string
- func WriteToFile(dir string, fileName string, data []byte) error
- type ApiService
- type ColumnSchema
- type Field
- type StructInfo
- type TypeMapping
- type ZeroConfig
- type ZeroGen
- type ZeroGenCore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateApiService ¶
func GenerateGetByIdLogic ¶
func GenerateGormModel ¶
func GenerateGormModel( modelPkgName string, homeDir string, tableName string, columns []ColumnSchema, typeMappings map[string]TypeMapping) (string, error)
GenerateStruct generates a struct based on the schema info using Go templates
func GetCopyTemplate ¶
func GetCreateTemplate ¶
func GetDeleteTemplate ¶
func GetGetByIdTemplate ¶
func GetGetListTemplate ¶
func GetGoZeroApiTemplate ¶
func GetGormModelTemplate ¶
func GetTypeMappings ¶
func GetTypeMappings(homeDir string) (map[string]TypeMapping, error)
func GetUpdateTemplate ¶
func ToLowerCamelCase ¶
ToLowerCamelCase converts snake_case to lowerCamelCase
func ToSnakeCase ¶
ToSnakeCase converts a string from camelCase or PascalCase to snake_case using a state machine approach
Types ¶
type ApiService ¶
type ColumnSchema ¶
type ColumnSchema struct { ColumnName string // Column name, e.g., "id", "created_at" ColumnType string // Column type, e.g., "uuid", "text" Nullable bool // Column nullable, e.g., true, false Length int64 // Column length, e.g., 128, 9223372036854775807 DefaultValue *string // Default value of the column, e.g., "now()" Comment string // Column comment, e.g., "Primary key", "Created time" }
ColumnSchema represents the schema of a database column
func GetTableSchema ¶
func GetTableSchema(db *gorm.DB, tableName string) ([]ColumnSchema, error)
type Field ¶
type Field struct { FieldName string // Go 结构体字段名(驼峰) FieldType string // Go 类型 JSONName string // JSON 序列化字段名 SnakeCaseName string // Tag name in snake_case format CopyGoZeroToGorm string `yaml:"copyGoZeroToGorm"` CopyGormToGoZero string `yaml:"copyGormToGoZero"` Nullable bool Comment string // Column comment }
type StructInfo ¶
type TypeMapping ¶
type TypeMapping struct { Default string `yaml:"default"` Gorm string `yaml:"gorm"` Gozero string `yaml:"gozero"` GormImportPath string `yaml:"gormImportPath"` CopyGoZeroToGorm string `yaml:"copyGoZeroToGorm"` CopyGormToGoZero string `yaml:"copyGormToGoZero"` CopyPath string `yaml:"copyPath"` }
func GoType ¶
func GoType(columnType string, nullable bool, typeMappings map[string]TypeMapping, framework string, usePtr bool, ) (string, string, TypeMapping)
GoType returns the Go type for a given database column type based on the framework type mapping, using "default" mapping if no specific framework mapping exists.
type ZeroConfig ¶
type ZeroConfig struct { Version string `yaml:"version"` Global zeroConfigWithAction `yaml:"global"` Local []zeroConfigWithAction `yaml:"local"` }
type ZeroGen ¶
type ZeroGen struct { ConfigFile string `clop:"-f;long" usage:"local configuration file path"` ZeroGenCore }
func (*ZeroGen) GenerateCRUDLogic ¶
func (z *ZeroGen) GenerateCRUDLogic( columnSchema []ColumnSchema, packageName string) (string, error)
GenerateCRUDLogic generates CRUD logic code for a given model
func (*ZeroGen) GenerateCopyFuncs ¶
func (z *ZeroGen) GenerateCopyFuncs(homeDir string, copyDir string, tableName string, schema []ColumnSchema, typeMappings map[string]TypeMapping) (string, error)
type ZeroGenCore ¶
type ZeroGenCore struct { Dsn string `clop:"long" usage:"database dsn" yaml:"dsn"` ModelDir string `clop:"long" usage:"gorm model output directory" yaml:"modelDir"` GoZeroApiDir string `clop:"long" usage:"go zero api output directory" yaml:"goZeroApiDir"` CopyDir string `clop:"long" usage:"copy functions output directory" yaml:"copyDir"` CrudLogicDir string `clop:"long" usage:"crud logic output directory" yaml:"crudLogicDir"` Table string `clop:"long" usage:"table name" yaml:"table"` Home string `clop:"long" usage:"template home directory" yaml:"home"` Debug bool `clop:"long" usage:"debug mode" yaml:"debug"` ModelPkgName string `clop:"long" usage:"gorm model package name" default:"models" yaml:"modelPkgName"` ApiPrefix string `clop:"long" usage:"go zero api file name prefix" yaml:"apiPrefix"` ServiceName string `clop:"long" usage:"go zero api service name" yaml:"serviceName"` ApiGroup string `clop:"long" usage:"go zero api group name" yaml:"apiGroup"` ImportPathPrefix string `clop:"long" usage:"copy module import path prefix" yaml:"importPathPrefix"` ApiUrlPrefix string `clop:"long" usage:"api url prefix" default:"/api/v1" yaml:"apiUrlPrefix"` CreateHook bool `clop:"long" usage:"generate create hook" yaml:"createHook"` UpdateHook bool `clop:"long" usage:"generate update hook" yaml:"updateHook"` GetListHook bool `clop:"long" usage:"generate get list hook" yaml:"getListHook"` GetByIdHook bool `clop:"long" usage:"generate get by id hook" yaml:"getByIdHook"` SaveModels *bool `clop:"long" usage:"save models to file" yaml:"saveModels"` SaveApi *bool `clop:"long" usage:"save api to file" yaml:"saveApi"` SaveCopy *bool `clop:"long" usage:"save copy to file" yaml:"saveCopy"` SaveCrudLogic *bool `clop:"long" usage:"save crud logic to file" yaml:"saveCrudLogic"` }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.