generators

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoFilePostfix    = ".proto"
	RestProtoFilePrefix = "i_"
)
View Source
const (
	// ProtoTypeTimestamp 表示 google.protobuf.Timestamp 类型
	ProtoTypeTimestamp = "google.protobuf.Timestamp"

	// SqlTypeDate DATE 类型(proto string, ent time.Time)
	SqlTypeDate = "DATE"

	// SqlTypeDecimal DECIMAL 类型(proto string, ent float64)
	SqlTypeDecimal = "DECIMAL"

	// ProtoTypeString 表示 proto string 类型
	ProtoTypeString = "string"
)

Variables

This section is empty.

Functions

func MakeEntSetFunc

func MakeEntSetFunc(fieldName string) string

func MakeEntSetFuncWithStringPtrNumTransfer

func MakeEntSetFuncWithStringPtrNumTransfer(fieldName string, transFunc string) string

MakeEntSetFuncWithStringPtrNumTransfer 用于非空 DECIMAL 等字段: proto string 值 -> ent float64 值 通过取地址转换后解引用:*StringPtrToFloat64Ptr(&val)

func MakeEntSetFuncWithTransfer

func MakeEntSetFuncWithTransfer(fieldName string, transFunc string) string

func MakeEntSetNillableFunc

func MakeEntSetNillableFunc(fieldName string) string

func MakeEntSetNillableFuncWithTransfer

func MakeEntSetNillableFuncWithTransfer(fieldName string, transFunc string) string

func RemoveTableCommentSuffix

func RemoveTableCommentSuffix(input string) string

func ServerFormalParameters

func ServerFormalParameters(servers []string) []string

ServerFormalParameters 形参

func ServerImportPaths

func ServerImportPaths(servers []string) []string

ServerImportPaths returns the import paths for the given server types.

func ServerTransferParameters

func ServerTransferParameters(servers []string) []string

ServerTransferParameters 实参

func SnakeToPascal

func SnakeToPascal(snake string) string

SnakeToPascal converts a snake_case string to PascalCase.

func SnakeToPascalPlus

func SnakeToPascalPlus(snake string) string

Types

type DataField

type DataField struct {
	Name         string // 字段名
	Type         string // 字段类型(Proto类型)
	SqlType      string // 原始SQL类型(大写,如 DATE, TIMESTAMP, VARCHAR 等)
	Comment      string // 字段注释
	Null         bool   // 是否允许为 NULL
	IsPrimaryKey bool   // 是否为主键
}

DataField 数据库字段定义

func (DataField) CamelName

func (f DataField) CamelName() string

func (DataField) EntCreateSetFunc

func (f DataField) EntCreateSetFunc() string

EntCreateSetFunc 根据字段是否可为 NULL 以及类型选择合适的 setter: NOT NULL + Timestamp → SetXxx(timeutil.TimestamppbToTime(req.Data.GetXxx())) NOT NULL + Date → SetXxx(timeutil.StringDateToTime(req.Data.GetXxx())) NOT NULL → SetXxx(req.Data.GetXxx()) NULL + Timestamp → SetNillableXxx(timeutil.TimestamppbToTime(req.Data.Xxx)) NULL + Date → SetNillableXxx(timeutil.StringDateToTime(req.Data.Xxx)) NULL → SetNillableXxx(req.Data.Xxx)

func (DataField) EntPascalName

func (f DataField) EntPascalName() string

func (DataField) EntSetNillableFunc

func (f DataField) EntSetNillableFunc() string

func (DataField) IsDateType

func (f DataField) IsDateType() bool

IsDateType 判断字段是否为 SQL DATE 类型(proto string, ent time.Time)

func (DataField) IsDecimalType

func (f DataField) IsDecimalType() bool

IsDecimalType 判断字段是否为 SQL DECIMAL 类型(proto string, ent float64)

func (DataField) IsTimestampType

func (f DataField) IsTimestampType() bool

IsTimestampType 判断字段是否为 Timestamp 类型

func (DataField) NeedsStringNumConversion

func (f DataField) NeedsStringNumConversion() bool

NeedsStringNumConversion 判断字段是否需要 stringutil 字符串指针转数字指针转换 条件:proto 类型为 string,且 SQL 类型为 DECIMAL

func (DataField) NeedsTimeConversion

func (f DataField) NeedsTimeConversion() bool

NeedsTimeConversion 判断字段是否需要 timeutil 转换

func (DataField) PascalName

func (f DataField) PascalName() string

func (DataField) SnakeName

func (f DataField) SnakeName() string

func (DataField) StringNumConvertFunc

func (f DataField) StringNumConvertFunc() string

StringNumConvertFunc 返回字符串转数字的转换函数名

func (DataField) TimeConvertFunc

func (f DataField) TimeConvertFunc() string

TimeConvertFunc 返回时间转换函数名

type DataFieldArray

type DataFieldArray []DataField

func (DataFieldArray) HasStringNumConversionField

func (f DataFieldArray) HasStringNumConversionField() bool

HasStringNumConversionField 检查字段数组中是否有需要 stringutil 转换的字段(DECIMAL 等)

func (DataFieldArray) HasTimeConversionField

func (f DataFieldArray) HasTimeConversionField() bool

HasTimeConversionField 检查字段数组中是否有需要 timeutil 转换的字段(Timestamp 或 Date)

type GoGenerator

type GoGenerator struct {
	*code_generator.CodeGenerator
}

GoGenerator 使用 TemplateEngine 渲染并将结果写入磁盘

func NewGoGenerator

func NewGoGenerator() *GoGenerator

NewGoGenerator 创建生成器,engine 可为 nil(需要在调用前设置)

func (*GoGenerator) CheckProviderSetFunctionExists

func (g *GoGenerator) CheckProviderSetFunctionExists(filePath string, functionCall string) (bool, error)

CheckProviderSetFunctionExists 检查 ProviderSet 中是否存在指定函数

func (*GoGenerator) EnsureImport

func (g *GoGenerator) EnsureImport(filePath string, importPath string) error

EnsureImport 确保文件中包含指定的 import 路径,不存在则添加

func (*GoGenerator) GenerateAssets

func (g *GoGenerator) GenerateAssets(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateEntClient

func (g *GoGenerator) GenerateEntClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateEntRepo

func (g *GoGenerator) GenerateEntRepo(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateGormClient

func (g *GoGenerator) GenerateGormClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateGormInit

func (g *GoGenerator) GenerateGormInit(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateGormRepo

func (g *GoGenerator) GenerateGormRepo(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateGrpcClient

func (g *GoGenerator) GenerateGrpcClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateGrpcServer

func (g *GoGenerator) GenerateGrpcServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateMain

func (g *GoGenerator) GenerateMain(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateRedisClient

func (g *GoGenerator) GenerateRedisClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateRestServer

func (g *GoGenerator) GenerateRestServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateService

func (g *GoGenerator) GenerateService(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateWire

func (g *GoGenerator) GenerateWire(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) GenerateWireSet

func (g *GoGenerator) GenerateWireSet(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*GoGenerator) UpsertMigrateModels

func (g *GoGenerator) UpsertMigrateModels(filePath string, models []string) error

UpsertMigrateModels 向 gorm_init.go 的 RegisterMigrateModels 中追加新模型 models: 模型名列表(单数形式,如 "game"),会被转为 PascalCase

func (*GoGenerator) UpsertProviderSetFunction

func (g *GoGenerator) UpsertProviderSetFunction(filePath string, functionCall string) error

UpsertProviderSetFunction 向 ProviderSet 中添加函数,如果不存在则新增 filePath: wire.go 文件路径 functionCall: 要添加的函数调用,如 "server.NewRestServer"

func (*GoGenerator) UpsertProviderSetFunctions

func (g *GoGenerator) UpsertProviderSetFunctions(filePath string, functionCalls []string) error

UpsertProviderSetFunctions 批量向 ProviderSet 中添加函数

type MakefileGenerator

type MakefileGenerator struct {
	*code_generator.CodeGenerator
}

MakefileGenerator 使用 TemplateEngine 渲染并将结果写入磁盘

func NewMakefileGenerator

func NewMakefileGenerator() *MakefileGenerator

NewMakefileGenerator 创建生成器,engine 可为 nil(需要在调用前设置)

func (*MakefileGenerator) GenerateAppMakefile

func (g *MakefileGenerator) GenerateAppMakefile(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

type ProtoField

type ProtoField struct {
	Name    string // 字段名
	Type    string // 字段类型
	Null    bool   // 是否允许为 NULL
	Comment string // 字段注释
	Number  int    // 字段编号
}

ProtoField 字段数据

type ProtoGenerator

type ProtoGenerator struct {
	*code_generator.CodeGenerator
}

ProtoGenerator 使用 TemplateEngine 渲染并将结果写入磁盘

func NewProtoGenerator

func NewProtoGenerator() *ProtoGenerator

NewProtoGenerator 创建生成器,engine 可为 nil(需要在调用前设置)

func (*ProtoGenerator) GenerateGrpcServiceProto

func (g *ProtoGenerator) GenerateGrpcServiceProto(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*ProtoGenerator) GenerateRestServiceProto

func (g *ProtoGenerator) GenerateRestServiceProto(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

type SchemaConverter

type SchemaConverter interface {
	SchemaTables(context.Context) ([]*TableData, error)
}

type TableData

type TableData struct {
	Name      string       // 表名
	Comment   string       // 表注释
	Charset   string       // 字符集
	Collation string       // 排序规则
	Fields    []ProtoField // 字段数据
}

TableData 表数据

func (TableData) WithComment

func (t TableData) WithComment() bool

type YamlGenerator

type YamlGenerator struct {
	*code_generator.CodeGenerator
}

YamlGenerator 使用 TemplateEngine 渲染并将结果写入磁盘

func NewYamlGenerator

func NewYamlGenerator() *YamlGenerator

NewYamlGenerator 创建生成器,engine 可为 nil(需要在调用前设置)

func (*YamlGenerator) GenerateClientYaml

func (g *YamlGenerator) GenerateClientYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*YamlGenerator) GenerateDataYaml

func (g *YamlGenerator) GenerateDataYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*YamlGenerator) GenerateLoggerYaml

func (g *YamlGenerator) GenerateLoggerYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

func (*YamlGenerator) GenerateServerYaml

func (g *YamlGenerator) GenerateServerYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)

Directories

Path Synopsis
templates

Jump to

Keyboard shortcuts

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