astutils

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExprString added in v0.2.6

func ExprString(expr ast.Expr) string

func FixImport added in v0.1.4

func FixImport(src []byte, file string)

func GetImportPath

func GetImportPath(file string) string

func GetMod

func GetMod() string

func RewriteJsonTag added in v0.2.6

func RewriteJsonTag(file string, omitempty bool, convert func(old string) string) (string, error)
Example
file := pathutils.Abs("testfiles/rewritejsontag.go")
result, err := RewriteJsonTag(file, true, strcase.ToLowerCamel)
if err != nil {
	panic(err)
}
fmt.Println(result)
Output:

package main

type base struct {
	Index string `json:"index,omitempty"`
	Type  string `json:"type,omitempty"`
}

type struct1 struct {
	base
	Name       string `json:"name,omitempty"`
	StructType int    `json:"structType,omitempty" dd:"awesomtag"`
	Format     string `dd:"anothertag" json:"format,omitempty"`
	Pos        int    `json:"pos,omitempty"`
}

func Visit

func Visit(files *[]string) filepath.WalkFunc

Types

type FieldMeta

type FieldMeta struct {
	Name     string
	Type     string
	Tag      string
	Comments []string
	IsExport bool
	DocName  string
}

type InterfaceCollector added in v0.1.4

type InterfaceCollector struct {
	Interfaces []InterfaceMeta
	Package    PackageMeta
	// contains filtered or unexported fields
}

func BuildInterfaceCollector added in v0.2.6

func BuildInterfaceCollector(file string, exprString func(ast.Expr) string) InterfaceCollector

func NewInterfaceCollector added in v0.2.6

func NewInterfaceCollector(exprString func(ast.Expr) string) *InterfaceCollector

func (*InterfaceCollector) Collect added in v0.1.4

func (ic *InterfaceCollector) Collect(n ast.Node) ast.Visitor

func (*InterfaceCollector) Visit added in v0.1.4

func (ic *InterfaceCollector) Visit(n ast.Node) ast.Visitor

type InterfaceMeta added in v0.1.4

type InterfaceMeta struct {
	Name     string
	Methods  []MethodMeta
	Comments []string
}

type MethodMeta added in v0.1.4

type MethodMeta struct {
	Recv     string
	Name     string
	Params   []FieldMeta
	Results  []FieldMeta
	Comments []string
}

func GetMethodMeta added in v0.2.6

func GetMethodMeta(spec *ast.FuncDecl) MethodMeta

func NewMethodMeta added in v0.2.6

func NewMethodMeta(ft *ast.FuncType, exprString func(ast.Expr) string) MethodMeta

func (MethodMeta) String added in v0.2.6

func (mm MethodMeta) String() string

type PackageMeta

type PackageMeta struct {
	Name string
}

type StructCollector

type StructCollector struct {
	Structs          []StructMeta
	Methods          map[string][]MethodMeta
	Package          PackageMeta
	NonStructTypeMap map[string]ast.Expr
	// contains filtered or unexported fields
}

func BuildStructCollector added in v0.2.6

func BuildStructCollector(file string, exprString func(ast.Expr) string) StructCollector

func NewStructCollector added in v0.2.1

func NewStructCollector(exprString func(ast.Expr) string) *StructCollector

func (*StructCollector) Collect

func (sc *StructCollector) Collect(n ast.Node) ast.Visitor

func (*StructCollector) DocFlatEmbed added in v0.2.6

func (sc *StructCollector) DocFlatEmbed() []StructMeta

func (*StructCollector) Visit

func (sc *StructCollector) Visit(n ast.Node) ast.Visitor

type StructMeta

type StructMeta struct {
	Name     string
	Fields   []FieldMeta
	Comments []string
	Methods  []MethodMeta
	IsExport bool
}

func NewStructMeta added in v0.2.6

func NewStructMeta(structType *ast.StructType, exprString func(ast.Expr) string) StructMeta

Jump to

Keyboard shortcuts

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