Documentation ¶
Overview ¶
Package astx provides utilities and builders for go/ast package.
Index ¶
- func FieldsNames(fields []*ast.Field) []string
- func FieldsNamesEmbed(fields []*ast.Field) []string
- func FileAppend(file *ast.File, decl ...ast.Decl)
- func MergeFiles(dst *ast.File, files []*ast.File)
- func PkgFiles(pkg *ast.Package) []*ast.File
- func PkgNames(pkgs map[string]*ast.Package) []string
- func SelectPkg(pkgs map[string]*ast.Package) (*ast.Package, error)
- type FieldMatcher
- type ValBuilder
- func (vb *ValBuilder) Decl() *ast.GenDecl
- func (vb *ValBuilder) Field() *ast.Field
- func (vb *ValBuilder) Spec() *ast.ValueSpec
- func (vb *ValBuilder) WithName(name string) *ValBuilder
- func (vb *ValBuilder) WithNameNode(name *ast.Ident) *ValBuilder
- func (vb *ValBuilder) WithType(t *ast.Ident) *ValBuilder
- func (vb *ValBuilder) WithValue(value ast.Expr) *ValBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldsNames ¶ added in v0.3.0
FieldsNames returns all field names flattened into a single list.
func FieldsNamesEmbed ¶ added in v0.3.0
FieldsNamesEmbed returns all field names or names of embedded types (if not anonymous).
func FileAppend ¶
FileAppend appends provided declarations to the file.
func MergeFiles ¶
MergeFiles merge multiple files into a single file and merge the imports.
Types ¶
type FieldMatcher ¶ added in v0.3.0
type FieldMatcher struct { FieldNames func(fields []*ast.Field) []string NameEq func(a, b string) bool }
FieldMatcher is a configurable matcher for field lists.
type ValBuilder ¶
type ValBuilder struct {
// contains filtered or unexported fields
}
ValBuilder provides utilities to build a single key-value expression.
func (*ValBuilder) Decl ¶
func (vb *ValBuilder) Decl() *ast.GenDecl
Decl generate a key-value declaration.
func (*ValBuilder) Field ¶
func (vb *ValBuilder) Field() *ast.Field
Field generates a simple field type declaration from value.
func (*ValBuilder) Spec ¶
func (vb *ValBuilder) Spec() *ast.ValueSpec
Spec generates the key-value spec.
func (*ValBuilder) WithName ¶
func (vb *ValBuilder) WithName(name string) *ValBuilder
WithName sets name for the value.
func (*ValBuilder) WithNameNode ¶
func (vb *ValBuilder) WithNameNode(name *ast.Ident) *ValBuilder
WithNameNode uses provided ident node as a name for the value.
func (*ValBuilder) WithType ¶
func (vb *ValBuilder) WithType(t *ast.Ident) *ValBuilder
WithType sets type for the value.
func (*ValBuilder) WithValue ¶
func (vb *ValBuilder) WithValue(value ast.Expr) *ValBuilder
WithValue sets values for the value spec.