Documentation
¶
Overview ¶
Package analyzer provides AST analysis for struct types and converter registrations.
Index ¶
- func Dereference(t types.Type) types.Type
- func IsPointer(t types.Type) bool
- func IsSlice(t types.Type) bool
- func IsStruct(t types.Type) bool
- func NormalizeTypeKey(typeStr string, pkg *packages.Package) string
- func QualifiedTypeName(t types.Type) string
- func ShortTypeName(t types.Type) string
- func SliceElem(t types.Type) types.Type
- func TypeKeyFromTypes(t types.Type) string
- func TypeName(t types.Type) string
- func TypePkgPath(t types.Type) string
- type Analyzer
- type ConverterInfo
- type FieldInfo
- type MapTag
- type StructInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dereference ¶
Dereference removes pointer indirection from a type.
func NormalizeTypeKey ¶
NormalizeTypeKey normalizes a type key for consistent comparison.
func QualifiedTypeName ¶
QualifiedTypeName returns a fully qualified type name for a types.Type.
func ShortTypeName ¶
ShortTypeName returns a short type name suitable for function naming.
func TypeKeyFromTypes ¶
TypeKeyFromTypes creates a type key string from types.Type for registry lookup.
func TypePkgPath ¶
TypePkgPath returns the package path for a named type, or empty string.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer loads and analyzes Go packages.
func (*Analyzer) FindStruct ¶
FindStruct finds a struct type by name in a package.
func (*Analyzer) LoadPackage ¶
LoadPackage loads a package by its import path or directory.
func (*Analyzer) ResolveType ¶
ResolveType resolves a type string like "userpb.User" to its full information.
type ConverterInfo ¶
type ConverterInfo struct {
// SourceType is the source type (A in RegisterTo[A, B])
SourceType string
// TargetType is the target type (B in RegisterTo[A, B])
TargetType string
// FuncName is the qualified function name being registered
FuncName string
// FuncPkg is the package path where the function is defined
FuncPkg string
// HasError indicates if the converter returns an error
HasError bool
// Name is the converter name for named converters (empty for unnamed)
Name string
// Direction indicates "to" or "from"
Direction string
}
ConverterInfo holds information about a discovered converter registration.
func DiscoverConverters ¶
func DiscoverConverters(pkg *packages.Package) ([]ConverterInfo, error)
DiscoverConverters finds all automapper.Register* calls in a package.
type FieldInfo ¶
type FieldInfo struct {
// Name is the field name
Name string
// Type is the field's Go type
Type types.Type
// TypeStr is the string representation of the type
TypeStr string
// Tag is the raw struct tag (including backticks)
Tag string
// Exported indicates if the field is exported
Exported bool
}
FieldInfo holds information about a struct field.
type MapTag ¶
type MapTag struct {
// Ignore indicates map:"-" was specified
Ignore bool
// TargetName is the target field name if specified (e.g., map:"TargetName")
TargetName string
// Converter is the named converter to use (e.g., map:",conv=name")
Converter string
}
MapTag represents a parsed map:"..." struct tag.
func ParseMapTag ¶
ParseMapTag parses the map:"..." tag from a raw struct tag string. The raw tag includes backticks, e.g., `json:"name" map:"TargetName,conv=foo"`.
type StructInfo ¶
type StructInfo struct {
// Name is the type name (e.g., "User")
Name string
// PkgPath is the import path (e.g., "myproject/model")
PkgPath string
// PkgName is the package name (e.g., "model")
PkgName string
// Fields contains information about each exported field
Fields []FieldInfo
}
StructInfo holds information about a struct type.
func (*StructInfo) QualifiedName ¶
func (s *StructInfo) QualifiedName() string
QualifiedName returns the fully qualified type name (e.g., "model.User").