astutils

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 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
	// when generate client code from openapi3 spec json file, Params holds all method input parameters.
	// when generate client code from service interface in svc.go file, if there is struct type param, this struct type param will put into request body,
	// then others will be put into url as query string. if there is no struct type param and the api is a get request, all will be put into url as query string.
	// if there is no struct type param and the api is Not a get request, all will be put into request body as application/x-www-form-urlencoded data.
	// specailly, if there is one or more *multipart.FileHeader or []*multipart.FileHeader params, all will be put into request body as multipart/form-data data.
	Params []FieldMeta
	// response
	Results []FieldMeta
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, PathVars is parameters in url as path variable.
	PathVars []FieldMeta
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, HeaderVars is parameters in header.
	HeaderVars []FieldMeta
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, BodyParams is parameters in request body as query string.
	BodyParams *FieldMeta
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, BodyJson is parameters in request body as json.
	BodyJson *FieldMeta
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, Files is parameters in request body as multipart file.
	Files    []FieldMeta
	Comments []string
	// api path
	// not support when generate client code from service interface in svc.go file
	Path string
	// not support when generate client code from service interface in svc.go file
	// when generate client code from openapi3 spec json file, QueryParams is parameters in url as query string.
	QueryParams *FieldMeta
}

MethodMeta represented a api

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