parser

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasInterface added in v0.0.18

func HasInterface(pkg *types.Package, s Struct, interfaceName string) bool

func LoadPackages

func LoadPackages(packagePatterns ...string) (map[string]*types.Package, error)

Loads and type checks a package. Returns any errors encountered during loading or typechecking, otherwise returns the package's data. Useful for static type analysis with the types package instead of manually parsing the AST. A good explainer lives here: https://github.com/golang/example/tree/master/gotypes

Types

type Field

type Field struct {
	TypeInfo
	// contains filtered or unexported fields
}

func (Field) IsLocalType

func (f Field) IsLocalType() bool

Returns true if the field's type originates from the same package its parent struct is defined in.

func (Field) LookupTag

func (f Field) LookupTag(key string) (string, bool)

func (Field) String

func (f Field) String() string

type Struct

type Struct struct {
	TypeInfo
	// contains filtered or unexported fields
}

func ParseStructs

func ParseStructs(pkg *types.Package) ([]Struct, error)

We can iterate over the declarations at the package level a single time to extract all the data necessary for generation. Any new data that needs to be added to the struct definitions can be extracted here.

func (Struct) Fields

func (s Struct) Fields() []Field

func (Struct) Implements added in v0.0.18

func (s Struct) Implements(iface string) bool

func (Struct) LocalTypes

func (s Struct) LocalTypes() []TypeInfo

func (Struct) Name

func (s Struct) Name() string

func (Struct) PrintWithFieldError

func (s Struct) PrintWithFieldError(fieldIndex int, errMsg string) string

func (*Struct) SetInterface added in v0.0.18

func (s *Struct) SetInterface(iface string)

func (Struct) String

func (s Struct) String() string

Pretty prints the struct name and its fields. Useful for debugging.

type TypeInfo added in v0.0.18

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

func (TypeInfo) IsIterable added in v0.0.18

func (t TypeInfo) IsIterable() bool

Returns true if type is slice or array

func (TypeInfo) IsPointer added in v0.0.18

func (t TypeInfo) IsPointer() bool

func (TypeInfo) IsStruct added in v0.0.18

func (t TypeInfo) IsStruct() bool

func (TypeInfo) Name added in v0.0.18

func (t TypeInfo) Name() string

func (TypeInfo) PackageName added in v0.0.18

func (t TypeInfo) PackageName() string

func (TypeInfo) Position added in v0.0.18

func (t TypeInfo) Position() int

Position in the Package the type object was parsed from

func (TypeInfo) ToStructType added in v0.0.18

func (t TypeInfo) ToStructType() Struct

func (TypeInfo) Type added in v0.0.18

func (t TypeInfo) Type() string

e.g. ccc.UUID, []ccc.UUID

func (TypeInfo) TypeName added in v0.0.18

func (t TypeInfo) TypeName() string

Qualified type without array/slice/pointer prefix. e.g. *ccc.UUID -> ccc.UUID, []ccc.UUID -> ccc.UUID

func (TypeInfo) UnqualifiedType added in v0.0.18

func (t TypeInfo) UnqualifiedType() string

Type without package prefix. e.g. ccc.UUID -> UUID, []ccc.UUID -> []UUID

func (TypeInfo) UnqualifiedTypeName added in v0.0.18

func (t TypeInfo) UnqualifiedTypeName() string

Type without array/slice/pointer or package prefix. e.g. *ccc.UUID -> UUID, []ccc.UUID -> UUID

Jump to

Keyboard shortcuts

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