Documentation
¶
Index ¶
- Constants
- Variables
- func CleanBlockComment(text string) string
- func CleanCommentPrefix(line string) string
- func FormatPackage(packagePath string) ([]string, error)
- func IsErrorType(err error, errorType ErrorType) bool
- func NewDSLAnnotationMissingClosingParenError(keyword, input string, position int) error
- func NewDSLAnnotationMissingOpeningParenError(keyword, input string, position int) error
- func NewDSLArrayEntryTypeError(key, expected string, actual any) error
- func NewDSLArrayMissingClosingBracketError(position int) error
- func NewDSLDuplicateKeyError(key string, position int) error
- func NewDSLEmptyArrayError(key string) error
- func NewDSLFieldNotFoundError(field, structName string) error
- func NewDSLIndexDuplicateError(indexName, fields string) error
- func NewDSLIndexFieldDuplicateError(indexName, field string) error
- func NewDSLInvalidNumberError(numberStr string, position int) error
- func NewDSLInvalidPrimaryKeyError(value, reason string) error
- func NewDSLMissingBraceError(position int) error
- func NewDSLTokenizeError(input string, position int, char byte) error
- func NewDSLUnclosedStringError(input string, position int) error
- func NewDSLUnexpectedObjectTokenError(actual string, position int) error
- func NewDSLUnexpectedTokenError(expected, actual string, position int) error
- func NewDSLUnexpectedTopLevelTokenError(actual string, position int) error
- func NewDSLUnexpectedValueTokenError(actual string, position int) error
- func NewDSLUnknownIndexKeyError(actual string) error
- func NewDSLUnknownTableKeyError(actual string) error
- func NewDSLValueTypeError(key, expected string, actual any) error
- func NewDuplicateEmbeddedError(typeName, structName string) error
- func NewDuplicateFieldError(fieldName, structName string) error
- func NewEmbeddedCycleError(structName string) error
- func NewFieldInvalidSelectorError(selectorExpr any) error
- func NewFieldUnsupportedCompositionError(description string) error
- func NewFieldUnsupportedTypeError(typeExpr any) error
- func NewPackageImportError(packagePath string, cause error) error
- func Parse(packagePath string) ([]*genmodel.StructInfo, string, error)
- func ParseTableInfo(structName string, commentGroup []*ast.CommentGroup, ...) (*genmodel.TableMeta, error)
- type DSLArray
- type DSLBool
- type DSLNode
- type DSLNumber
- type DSLObject
- type DSLString
- type ErrorType
- type FieldTags
- type ParseResult
- type ParseState
- type Parser
- type ParserError
- type StructInfo
- type Token
- type TokenType
Constants ¶
const ( TSQFileSuffix = ".tsq.go" GoFileSuffix = ".go" )
const ( TagDB = "db" TagTSQ = "tsq" TagJSON = "json" )
const ( DefaultPKField = "ID" DefaultVersionField = "Version" DefaultCreatedAtField = "CreatedAt" DefaultUpdatedAtField = "UpdatedAt" DefaultDeletedAtField = "DeletedAt" )
默认字段名常量
const (
TagIgnore = "-"
)
Variables ¶
var PrimitiveTypes = map[string]struct{}{
"bool": {},
"string": {},
"int": {},
"int8": {},
"int16": {},
"int32": {},
"int64": {},
"uint": {},
"uint8": {},
"uint16": {},
"uint32": {},
"uint64": {},
"uintptr": {},
"byte": {},
"rune": {},
"float32": {},
"float64": {},
"complex64": {},
"complex128": {},
}
Functions ¶
func CleanCommentPrefix ¶
CleanCommentPrefix 去除一行注释的前缀和多余空白
func FormatPackage ¶
FormatPackage rewrites TSQ DSL annotations for one Go package and returns the files that changed.
func NewDSLDuplicateKeyError ¶
NewDSLDuplicateKeyError 创建 DSL 重复 key 错误
func NewDSLEmptyArrayError ¶
func NewDSLFieldNotFoundError ¶
NewDSLFieldNotFoundError 创建 DSL 字段不存在错误
func NewDSLIndexDuplicateError ¶
NewDSLIndexDuplicateError 创建索引定义重复错误
func NewDSLIndexFieldDuplicateError ¶
NewDSLIndexFieldDuplicateError 创建索引字段重复错误
func NewDSLInvalidNumberError ¶
NewDSLInvalidNumberError 创建 DSL 无效数字错误
func NewDSLMissingBraceError ¶
func NewDSLTokenizeError ¶
NewDSLTokenizeError 创建 DSL 词法分析错误
func NewDSLUnclosedStringError ¶
NewDSLUnclosedStringError 创建 DSL 未闭合字符串错误
func NewDSLUnexpectedTokenError ¶
NewDSLUnexpectedTokenError 创建 DSL 意外 token 错误
func NewDSLValueTypeError ¶
func NewDuplicateEmbeddedError ¶
NewDuplicateEmbeddedError 创建重复嵌入类型错误
func NewDuplicateFieldError ¶
NewDuplicateFieldError 创建重复字段错误
func NewEmbeddedCycleError ¶
NewEmbeddedCycleError 创建嵌入结构体循环引用错误
func NewFieldInvalidSelectorError ¶
NewFieldInvalidSelectorError 创建字段无效选择器错误
func NewFieldUnsupportedTypeError ¶
NewFieldUnsupportedTypeError 创建字段不支持类型错误
func NewPackageImportError ¶
NewPackageImportError 创建包导入错误
Types ¶
type ErrorType ¶
type ErrorType int
ErrorType 表示错误类型
const ( // Package 相关错误 ErrorTypePackageImport ErrorType = iota // Struct 相关错误 ErrorTypeDuplicateField ErrorTypeDuplicateEmbedded ErrorTypeEmbeddedCycle // DSL 相关错误 ErrorTypeDSLTokenize ErrorTypeDSLUnexpectedToken ErrorTypeDSLUnexpectedValue ErrorTypeDSLUnclosedString ErrorTypeDSLInvalidNumber ErrorTypeDSLMissingBracket ErrorTypeDSLMissingBrace ErrorTypeDSLDuplicateKey // Field 相关错误 ErrorTypeFieldUnsupportedType ErrorTypeFieldInvalidSelector // DSL 字段和索引校验 ErrorTypeDSLFieldNotFound ErrorTypeDSLIndexFieldDuplicate ErrorTypeDSLIndexDuplicate )
type ParseResult ¶
type ParseResult struct {
Structs []*StructInfo // 解析到的结构体列表
Directory string // 目标目录路径
}
ParseResult 解析结果
type ParseState ¶
type ParseState struct {
// contains filtered or unexported fields
}
ParseState 包含解析过程中的状态信息
type ParserError ¶
ParserError 表示解析器错误
func (*ParserError) GetContext ¶
func (e *ParserError) GetContext() map[string]any
GetContext 返回错误上下文
type StructInfo ¶
type StructInfo struct {
*genmodel.StructInfo
// contains filtered or unexported fields
}
StructInfo 表示一个解析后的结构体信息