packagex

package module
v0.0.0-...-28620a2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 5 Imported by: 0

README

packagex

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotTypeSpec = errors.New("not a type spec")
View Source
var ErrTagNotFound = errors.New("tag not found")

Functions

func Do

func Do()

func FieldType

func FieldType(expr ast.Expr) string

FieldName return the name of the struct field

func TagValue

func TagValue(tag string, key string, subkey string) (string, error)

Tagvalue extract tag value

Types

type Book

type Book struct {
	Name    string
	Content struct {
		Text string
	}
}

type BookWithTag

type BookWithTag struct {
	Name   string `json:"name,omitempty" gorm:"column:book;type:varchar(255);"`
	Author string `json:"author,omitempty" gorm:"column:author;type:varchar(30);"`
}

type BookWithTypeParam

type BookWithTypeParam[T any] struct {
	Name  string
	Value T
}

type Context

type Context struct {
	FileContext
	GenDecl *ast.GenDecl
}

func (Context) TypeName

func (ctx Context) TypeName() string

func (Context) TypeParams

func (ctx Context) TypeParams() (fieldList *ast.FieldList)

type FileContext

type FileContext struct {
	File    *ast.File
	Package *packages.Package
}

func (FileContext) FileName

func (ctx FileContext) FileName() string

type User

type User struct {
	Name string
	Age  int
}

func (User) Buy

func (u User) Buy(b *Book) error

type Visitor

type Visitor struct {
	ValueVisitor        func(*ast.ValueSpec, Context) error
	ImportVisitor       func(*ast.ImportSpec, Context) error
	StructVisitor       func(*ast.StructType, Context) error
	IdentVisitor        func(*ast.Ident, Context) error
	CompositeLitVisitor func(*ast.CompositeLit, Context) error
	// contains filtered or unexported fields
}

func (*Visitor) Walk

func (v *Visitor) Walk(cfg *packages.Config, pattern ...string) error

Walk walks the packages matched with the same rule as packages: https://pkg.go.dev/golang.org/x/tools/go/packages, calling inside visitor function for each top declaration in each file of the packages

# Walk will return immediately once any visitor function have error

func (*Visitor) WithFileFilter

func (v *Visitor) WithFileFilter(f func(FileContext) bool) *Visitor

Jump to

Keyboard shortcuts

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