Help us shape the future of Go! Take the 2026 Go Developer Survey

infra

package
v1.12.19 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const HashMethods = `` /* 5164-byte string literal not displayed */
View Source
const HashTemplStr = `` /* 1199-byte string literal not displayed */
View Source
const StringMethods = `` /* 2318-byte string literal not displayed */
View Source
const StringTemplStr = `` /* 899-byte string literal not displayed */

Variables

View Source
var TemplateFuncMap = template.FuncMap{
	"GetValues":        templateGetValues,
	"GetArgs":          templateGetArgs,
	"GetTypeList":      templateGetTypeList,
	"GetShardArg":      templateGetShardArg,
	"GetBatchShardArg": templateGetBatchShardArg,
	"HasAnyFields":     templateHasAnyFields,
	"JoinArgs":         templateJoinArgs,
	"JoinArgsTrail":    templateJoinArgsTrail,
	"ShardArgDecl":     templateShardArgDecl,
	"NotUidArgs":       templateNotUidArgs,
	"CtxCallArgs":      templateCtxCallArgs,
	"LocalCallArgs":    templateLocalCallArgs,
	"HasUidField":      templateHasUidField,
	"fieldCount":       templateFieldCount,
}

TemplateFuncMap 模板函数映射,供模板渲染时使用

Functions

func BuildHashTemplate

func BuildHashTemplate() (*template.Template, error)

BuildHashTemplate 构建Hash类型的Go代码模板

func BuildStringTemplate

func BuildStringTemplate() (*template.Template, error)

BuildStringTemplate 构建String类型的Go代码模板

func ParseDbSpec

func ParseDbSpec(dbSpec string) (dbType domain.DbType, dbName string, shardField *domain.Field)

ParseDbSpec 解析数据库规格字符串,返回 (DbType, 静态DbName/常量引用, ShardField) 支持格式:

  • "MyDb" -> (Static, "MyDb", nil) 静态数据库名字面量
  • "global:ConstRef" -> (Global, "ConstRef", nil) 全局常量引用(无函数参数) 例如 global:database.REDIS_GLOBAL,其中 database.REDIS_GLOBAL 必须是业务层 database 包自己定义的字符串常量,生成代码时原样透传为 redispool.Get(database.REDIS_GLOBAL)
  • "global:Name@string" -> (Global, "", &Field{Name:"Name"}) 全局运行时参数
  • "shards:uid@uint64" -> (Shards, "", &Field{...}) 分片路由参数

func ParseFieldFormat

func ParseFieldFormat(str string) (format string, fields []*domain.Field)

ParseFieldFormat 解析字段格式串 "key:name@type,name2@type2" -> (格式化串, 字段列表) 支持两种格式:

  • "prefix:Name@type" → 格式串 "prefix:%d", fields=[{Name,type}] (带前缀)
  • "Name@type" → 格式串 "%d", fields=[{Name,type}] (无前缀,纯参数)

这是纯函数,无副作用,可被领域层或基础设施层安全调用

Types

type ASTParser

type ASTParser struct {
	// contains filtered or unexported fields
}

ASTParser 基础设施层:AST源码解析器 职责:将Go源码中的 @dbtool 注解解析为领域模型(RedisString/RedisHash)

func NewASTParser

func NewASTParser(ctx *domain.ParseContext) *ASTParser

NewASTParser 创建AST解析器

func (*ASTParser) GetContext

func (p *ASTParser) GetContext() *domain.ParseContext

GetContext 返回填充后的领域上下文(供外部获取解析结果)

func (*ASTParser) Visit

func (p *ASTParser) Visit(n ast.Node) ast.Visitor

Visit 实现ast.Visitor接口,遍历AST提取@dbtool注解定义的模型

type FileWriter

type FileWriter struct {
	// contains filtered or unexported fields
}

FileWriter 文件系统输出适配器,实现 domain.OutputPort 接口

func NewFileWriter

func NewFileWriter(dstDir string) *FileWriter

NewFileWriter 创建文件写入器

func (*FileWriter) Write

func (w *FileWriter) Write(filename string, content []byte) error

Write 实现 OutputPort 接口

Jump to

Keyboard shortcuts

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