Documentation ¶
Index ¶
- Constants
- func FormatTypeExpr(expr ast.Expr) string
- func ResolvePackage(pkg *packages.Package, file *ast.File, name string) (*packages.Package, bool)
- func ResolveType(pkg *packages.Package, name string) (*ast.StructType, *ast.File, bool)
- func ResolveTypeExpr(pkg *packages.Package, file *ast.File, expr ast.Expr) (*ast.StructType, *ast.File, bool)
- type FieldType
- type StructType
Constants ¶
const Needs = packages.NeedName | packages.NeedDeps | packages.NeedFiles | packages.NeedSyntax | packages.NeedImports
Needs is the packages.Mode with all the flags required to find fields.
Variables ¶
This section is empty.
Functions ¶
func FormatTypeExpr ¶ added in v0.0.3
FormatTypeExpr poorly formats a subset of possible type expressions. TODO: make this method less terrible.
func ResolvePackage ¶
ResolvePackage will resolve a package by its name. It's legal to pass a nil file, but then import aliases and duplicates are not handled.
func ResolveType ¶
ResolveType returns a struct type defined in the provided package along with the file it's declared in. The bool return value will be false if the name could not be resolved.
func ResolveTypeExpr ¶ added in v0.0.3
func ResolveTypeExpr(pkg *packages.Package, file *ast.File, expr ast.Expr) (*ast.StructType, *ast.File, bool)
ResolveTypeExpr returns the struct type referred to by the provided expression. A nil file may be passed, but package resolution will not be accurate. The boom return value will be false if the type expression could not be resolved to a struct type.
Types ¶
type StructType ¶
StructType contains details about a struct and it's fields.
func Load ¶
func Load(dir string, patterns ...string) ([]*StructType, error)
Load finds all structs in the packages specified in the patterns. Embeded fields are treated the same as regular fields.
func Structs ¶
func Structs(pkg *packages.Package) []*StructType
Structs finds all structs in the provided package. Embeded fields are treated the same as regular fields.