Documentation
¶
Index ¶
- func Generate(ctx context.Context, opts GeneratorOptions) error
- func PlanTables(ctx context.Context, opts GeneratorOptions) (sqlproto.TableDataArray, error)
- type Generator
- func (g *Generator) Generate(ctx context.Context, opts GeneratorOptions) error
- func (g *Generator) WriteDataPackageCode(outputPath string, orm string, projectName string, serviceName string, ...) error
- func (g *Generator) WriteDataWireSetCode(outputPath string, projectModule string, serviceName string, ...) error
- func (g *Generator) WriteMainCode(outputPath string, projectName string, serviceName string, servers []string) error
- func (g *Generator) WriteServerPackageCode(outputPath string, projectName string, serviceType string, serviceName string, ...) error
- func (g *Generator) WriteServicePackageCode(outputPath string, projectName string, serviceName string, name string, ...) error
- func (g *Generator) WriteWireCode(outputPath string, projectName string, serviceName string) error
- func (g *Generator) WriteWireSetCode(outputPath string, projectModule string, serviceName string, ...) error
- type GeneratorOption
- func WithExcludedTables(tables []string) GeneratorOption
- func WithIncludedTables(tables []string) GeneratorOption
- func WithModuleName(name string) GeneratorOption
- func WithModuleVersion(ver string) GeneratorOption
- func WithOutputPath(path string) GeneratorOption
- func WithSource(dsn string) GeneratorOption
- func WithSourceModuleName(name string) GeneratorOption
- type GeneratorOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PlanTables ¶ added in v1.0.2
func PlanTables(ctx context.Context, opts GeneratorOptions) (sqlproto.TableDataArray, error)
PlanTables 只读解析数据源中将被处理的表(已应用 include/exclude 过滤), 不导出 proto、不生成任何文件。供 generate --dry-run 预览与校验数据源。
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func NewGenerator ¶
func NewGenerator() *Generator
func (*Generator) Generate ¶
func (g *Generator) Generate(ctx context.Context, opts GeneratorOptions) error
func (*Generator) WriteDataPackageCode ¶
func (*Generator) WriteDataWireSetCode ¶
func (g *Generator) WriteDataWireSetCode( outputPath string, projectModule string, serviceName string, allFunctions []string, ) error
WriteDataWireSetCode 生成 data 层的 wire_set,支持 client 和 data 两个包的函数
func (*Generator) WriteMainCode ¶
func (*Generator) WriteServerPackageCode ¶
func (*Generator) WriteServicePackageCode ¶
func (*Generator) WriteWireCode ¶
type GeneratorOption ¶
type GeneratorOption func(*GeneratorOptions)
func WithExcludedTables ¶
func WithExcludedTables(tables []string) GeneratorOption
func WithIncludedTables ¶
func WithIncludedTables(tables []string) GeneratorOption
func WithModuleName ¶
func WithModuleName(name string) GeneratorOption
func WithModuleVersion ¶
func WithModuleVersion(ver string) GeneratorOption
func WithOutputPath ¶
func WithOutputPath(path string) GeneratorOption
func WithSource ¶
func WithSource(dsn string) GeneratorOption
func WithSourceModuleName ¶
func WithSourceModuleName(name string) GeneratorOption
type GeneratorOptions ¶
type GeneratorOptions struct {
// Driver 仅在 Source 不带 scheme 时用于补全前缀,取值 mysql / postgres / postgresql;
// Source 自带 scheme(mysql://、postgres://、ent://、gorm://)或是 DDL 文本时留空即可。
Driver string
Source string // Data Source name (DSN), e.g., "mysql://user:pass@tcp(localhost:3306)/dbname"
IncludedTables []string
ExcludedTables []string
OutputPath string
SourceModuleName string // for REST service, the Source module name
ModuleName string
ModuleVersion string
// ProtoPackageStrategy controls how proto packages are organized.
// "per-table" - each table gets its own proto package (e.g. user.service.v1)
// "by-service" - all tables under a service share one proto package (e.g. admin.service.v1)
// "custom" - use the package name from TableCustomPackages for each table
ProtoPackageStrategy string
// TableCustomPackages maps table name -> custom proto package name.
// Only used when ProtoPackageStrategy is "custom".
TableCustomPackages map[string]string
OrmType string // ORM type, e.g., "gorm", "sqlx", "ent"
ProjectName string
ServiceName string
Servers []string
UseRepo bool
// GenerateTests 为生成的 CRUD service 追加单测骨架(fake 仓储,
// 消费方接口接缝)。仅在 gRPC + 本地仓储形态下产出。
GenerateTests bool
GenerateProto bool
GenerateServer bool
GenerateService bool
GenerateORM bool
GenerateData bool
GenerateMain bool
GenerateConfig bool
GenerateMakefile bool
}
Click to show internal directories.
Click to hide internal directories.