Documentation
¶
Index ¶
- Constants
- func ApiImportPath(serverKind string, module string, domain string, version string) string
- func ApiPackageAlias(name string, version string) string
- func ApplyAnchorPatches(patches ...AnchorPatch) error
- func BuildRepoWiringLine(model string, ormClientVar string) (line string, skipIf string)
- func BuildRouteLine(serverKind string, domain string, version string, model string) (line string, skipIf string)
- func BuildServerArgLine(model string) (line string, skipIf string)
- func BuildServerParamLine(model string) (line string, skipIf string)
- func BuildServiceWiringLine(model string, useClient bool) (line string, skipIf string)
- func ContentHasTrimmedLine(content string, anchor string) bool
- func DetectOrmClientVar(wiringFile string, orm string) string
- func FileHasTrimmedLine(path string, anchor string) bool
- func FindWiringFile(cmdServerDir string, ormPreference string) string
- func MakeEntSetFunc(fieldName string) string
- func MakeEntSetFuncWithStringPtrNumTransfer(fieldName string, transFunc string) string
- func MakeEntSetFuncWithTransfer(fieldName string, transFunc string) string
- func MakeEntSetNillableFunc(fieldName string) string
- func MakeEntSetNillableFuncWithTransfer(fieldName string, transFunc string) string
- func RemoveTableCommentSuffix(input string) string
- func RemoveWiringModuleLines(wiringFile string, model string) error
- func ServerFormalParameters(servers []string) []string
- func ServerImportPaths(servers []string) []string
- func ServerTransferParameters(servers []string) []string
- func SnakeToPascal(snake string) string
- func SnakeToPascalPlus(snake string) string
- func WireProvidersExist(serviceDir string) bool
- func WiringAnchorCandidates(kind string) []string
- type AnchorPatch
- type DataField
- func (f DataField) CamelName() string
- func (f DataField) EntCreateSetFunc() string
- func (f DataField) EntPascalName() string
- func (f DataField) EntSetNillableFunc() string
- func (f DataField) IsDateType() bool
- func (f DataField) IsDecimalType() bool
- func (f DataField) IsTimestampType() bool
- func (f DataField) NeedsStringNumConversion() bool
- func (f DataField) NeedsTimeConversion() bool
- func (f DataField) PascalName() string
- func (f DataField) SnakeName() string
- func (f DataField) StringNumConvertFunc() string
- func (f DataField) TimeConvertFunc() string
- type DataFieldArray
- type GoGenerator
- func (g *GoGenerator) CheckProviderSetFunctionExists(filePath string, functionCall string) (bool, error)
- func (g *GoGenerator) EnsureAliasedImport(filePath string, alias string, importPath string) error
- func (g *GoGenerator) EnsureImport(filePath string, importPath string) error
- func (g *GoGenerator) GenerateAssets(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateEntClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateEntRepo(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateGormClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateGormInit(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateGormRepo(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateGrpcClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateGrpcServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateMain(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateRedisClient(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateRestServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateService(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateWebsocketServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateWire(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateWireSet(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *GoGenerator) GenerateWiring(ctx context.Context, opts code_generator.Options, blocks WiringBlocks) (outputPath string, err error)
- func (g *GoGenerator) UpsertMigrateModels(filePath string, models []string) error
- func (g *GoGenerator) UpsertProviderSetFunction(filePath string, functionCall string) error
- func (g *GoGenerator) UpsertProviderSetFunctions(filePath string, functionCalls []string) error
- type MakefileGenerator
- type ProtoField
- type ProtoGenerator
- type WiringBlocks
- type WiringInfraClient
- type YamlGenerator
- func (g *YamlGenerator) GenerateClientYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *YamlGenerator) GenerateDataYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *YamlGenerator) GenerateLoggerYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
- func (g *YamlGenerator) GenerateServerYaml(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
Constants ¶
const ( AnchorRepo = "// ── register:repo ── 新模块仓储在此行后注册(make register 工具锚点,勿删)" AnchorClient = "// ── register:client ── 新模块服务客户端在此行后注册(make register 工具锚点,勿删)" AnchorService = "// ── register:service ── 新模块服务在此行后注册(make register 工具锚点,勿删)" AnchorRestArg = "// register:rest-arg ── 新模块服务实参在此行后追加(make register 工具锚点,勿删)" AnchorGrpcArg = "// register:grpc-arg ── 新模块服务实参在此行后追加(make register 工具锚点,勿删)" AnchorParam = "// register:param ── 新模块服务形参在此行后注册(make register 工具锚点,勿删)" AnchorRoute = "// register:route ── 新模块路由在此行后注册(make register 工具锚点,勿删)" )
register:* 锚点注释。注入式登记的落点,与参考工程(go-wind-admin / go-wind-cms)中 tools/register 及其 wiring/server 文件内嵌的锚点字符串逐字节一致,勿改动。
const ( ProtoFilePostfix = ".proto" RestProtoFilePrefix = "i_" )
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 ApiImportPath ¶ added in v1.0.2
ApiImportPath 构造 api 包的 import 路径,与 server 模板中的 import 语句逐字一致 (rest 模板的 module 段不转小写,grpc 模板整体转小写)。
func ApiPackageAlias ¶ added in v1.0.2
ApiPackageAlias 生成 api 包的 import 别名,与模板函数 apiPackageAlias 一致。
func ApplyAnchorPatches ¶ added in v1.0.2
func ApplyAnchorPatches(patches ...AnchorPatch) error
ApplyAnchorPatches 依次应用各锚点注入。任一锚点缺失即报错(漏锚点应显式失败而非静默跳过)。
func BuildRepoWiringLine ¶ added in v1.0.2
BuildRepoWiringLine 构造仓储层登记行(仓储型服务的 data 层构造)。
func BuildRouteLine ¶ added in v1.0.2
func BuildRouteLine(serverKind string, domain string, version string, model string) (line string, skipIf string)
BuildRouteLine 构造 server 文件的路由注册行。serverKind 为 "rest"(HTTP 网关)或 "grpc"(后端服务);domain 为路由所属 api 域模块名,version 为 api 包版本。
func BuildServerArgLine ¶ added in v1.0.2
BuildServerArgLine 构造传输层服务实参行(注入到 NewRestServer/NewGrpcServer 调用实参列表)。
func BuildServerParamLine ¶ added in v1.0.2
BuildServerParamLine 构造 server 文件的服务形参行。
func BuildServiceWiringLine ¶ added in v1.0.2
BuildServiceWiringLine 构造服务层登记行。useClient 为真时数据源为服务客户端变量(BFF), 否则为仓储变量。
func ContentHasTrimmedLine ¶ added in v1.0.2
ContentHasTrimmedLine 报告内容中是否存在(去空白后)与 anchor 完全一致的行。
func DetectOrmClientVar ¶ added in v1.0.2
DetectOrmClientVar 从既有装配文件中识别 ORM 客户端变量的实际命名 (如 entClient / client 等),供注入的仓储构造行引用;识别失败回退规范命名。
func FileHasTrimmedLine ¶ added in v1.0.2
FileHasTrimmedLine 报告文件中是否存在(去空白后)与 anchor 完全一致的行。
func FindWiringFile ¶ added in v1.0.2
FindWiringFile 在 cmd/server 目录下定位手写装配文件(wiring*.go)。 仅把包含任一 wiring 侧登记锚点(repo/client/service)的文件视为装配文件; ormPreference 非空时优先返回其中构造了对应 ORM 客户端的文件 (双文件形态如 wiring_ent.go/wiring_gorm.go 互斥构建标签), 否则回退到首个含锚点者;找不到返回空串。
func MakeEntSetFunc ¶
func MakeEntSetFuncWithStringPtrNumTransfer ¶
MakeEntSetFuncWithStringPtrNumTransfer 用于非空 DECIMAL 等字段: proto string 值 -> ent float64 值 通过取地址转换后解引用:*StringPtrToFloat64Ptr(&val)
func MakeEntSetNillableFunc ¶
func RemoveWiringModuleLines ¶ added in v1.0.2
RemoveWiringModuleLines 从装配文件中移除指定模块的全部登记行 (仓储/客户端构造行、服务构造行、传输层实参行),供模块迁出时清理源端。
func ServerFormalParameters ¶
ServerFormalParameters 形参
func ServerImportPaths ¶
ServerImportPaths returns the import paths for the given server types.
func ServerTransferParameters ¶
ServerTransferParameters 实参
func SnakeToPascal ¶
SnakeToPascal converts a snake_case string to PascalCase.
func SnakeToPascalPlus ¶
func WireProvidersExist ¶ added in v1.0.2
WireProvidersExist 报告服务目录下是否存在任一 wire provider 集 (internal/{data,service,server}/providers/wire_set.go),用于识别旧式 wire 形态的服务。
func WiringAnchorCandidates ¶ added in v1.0.2
WiringAnchorCandidates 注入 wiring 文件各登记位时可接受的锚点集合(按序探测,首个命中生效)。 不同服务形态的 wiring 文件带有不同的锚点:仓储型为 repo/grpc-arg,BFF 型为 client/rest-arg, 服务层锚点两形态同构。
Types ¶
type AnchorPatch ¶ added in v1.0.2
AnchorPatch 描述一次锚点注入: Path 目标文件;Anchors 候选锚点行(按去空白后的全文匹配,首个命中者生效); Lines 插入的行(不含行尾符);SkipIf 文件已包含该子串时跳过(幂等)。
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) EntCreateSetFunc ¶
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 (DataField) EntSetNillableFunc ¶
func (DataField) IsDateType ¶
IsDateType 判断字段是否为 SQL DATE 类型(proto string, ent time.Time)
func (DataField) IsDecimalType ¶
IsDecimalType 判断字段是否为 SQL DECIMAL 类型(proto string, ent float64)
func (DataField) IsTimestampType ¶
IsTimestampType 判断字段是否为 Timestamp 类型
func (DataField) NeedsStringNumConversion ¶
NeedsStringNumConversion 判断字段是否需要 stringutil 字符串指针转数字指针转换 条件:proto 类型为 string,且 SQL 类型为 DECIMAL
func (DataField) NeedsTimeConversion ¶
NeedsTimeConversion 判断字段是否需要 timeutil 转换
func (DataField) PascalName ¶
func (DataField) StringNumConvertFunc ¶
StringNumConvertFunc 返回字符串转数字的转换函数名
func (DataField) TimeConvertFunc ¶
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) EnsureAliasedImport ¶ added in v1.0.2
func (g *GoGenerator) EnsureAliasedImport(filePath string, alias string, importPath string) error
EnsureAliasedImport 确保文件中包含指定 import 的带别名形式,不存在则添加。 若该路径已以任意形式(带或不带别名)存在则跳过。
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) GenerateWebsocketServer ¶ added in v1.0.4
func (g *GoGenerator) GenerateWebsocketServer(ctx context.Context, opts code_generator.Options) (outputPath string, err error)
GenerateWebsocketServer 渲染 WebSocket 传输层骨架(internal/server/websocket_server.go)。 WebSocket 以消息类型驱动,不登记 proto 服务,故无需 Services/Packages 变量。
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) GenerateWiring ¶ added in v1.0.2
func (g *GoGenerator) GenerateWiring(ctx context.Context, opts code_generator.Options, blocks WiringBlocks) (outputPath string, err error)
GenerateWiring 渲染手写装配文件骨架(wiring.go),含分层小节、cleanup 注册表与登记锚点。 blocks 为各分节内容,由 BuildWiringBlocks 构造。
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 WiringBlocks ¶ added in v1.0.2
type WiringBlocks struct {
HeaderComment string
InfraBlock string
RepoBlock string
ServiceBlock string
TransportBlock string
NewAppArgs string
ImportData bool
ImportClient bool
ImportServer bool
ImportServicePkg bool
}
WiringBlocks 为 wiring.tpl 的全部渲染变量。
func BuildWiringBlocks ¶ added in v1.0.2
func BuildWiringBlocks( servers []string, useRepo bool, orm string, dbClients []string, repoModels []string, serviceModels []string, ) WiringBlocks
BuildWiringBlocks 构造全新装配文件的分节块。 repoModels 为本次生成产生了仓储文件的模型,serviceModels 为本次产生了服务文件的模型; 两者为空(纯脚手架)时各分节仅含锚点。orm 为仓储型服务的 ORM 类型(决定客户端变量命名), BFF 传空。dbClients 为要构造的基础设施客户端列表。
type WiringInfraClient ¶ added in v1.0.2
WiringInfraClient 描述基础设施小节中的一个客户端构造。
func WiringInfraClientFor ¶ added in v1.0.2
func WiringInfraClientFor(dbClient string) (WiringInfraClient, bool)
WiringInfraClientFor 把 dbClient 名称解析为基础设施描述符; 仅支持生成了对应 client 模板的类型(ent/gorm/redis),其余忽略。
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)