generate

package
v0.0.0-...-c3ec36b Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoLayouterError = errors.New("Layouter空")

Functions

func AddImport

func AddImport(root *ast.File, path string)

func FetchFuncDecl

func FetchFuncDecl(name string) *ast.FuncDecl

func Field

func Field(n *ast.Ident, t ast.Expr) *ast.Field

func FieldList

func FieldList(list ...*ast.Field) *ast.FieldList

func FormatNode

func FormatNode(fname string, node ast.Node) (*bytes.Buffer, error)

func InventName

func InventName(t ast.Expr, scope *ast.Scope) *ast.Ident

func MappedFieldList

func MappedFieldList(fn func(Arg) *ast.Field, args ...Arg) *ast.FieldList

func NewAstFile

func NewAstFile(pkgname string) *ast.File

func RegisterLayouter

func RegisterLayouter(name string, lay Layouter)

注册解析对象

func ScopeWith

func ScopeWith(names ...string) *ast.Scope

func Sel

func Sel(ids ...*ast.Ident) ast.Expr

func StructDecl

func StructDecl(name *ast.Ident, fields *ast.FieldList, comment ...*ast.CommentGroup) ast.Decl

func TypeOf

func TypeOf(tp interface{}) string

Types

type Arg

type Arg struct {
	Name, AsField *ast.Ident
	Typ           ast.Expr
	IsStar        bool //是否是指针
	IsError       bool
	IsBody        bool
}

func (Arg) Exported

func (a Arg) Exported() *ast.Field

func (Arg) Field

func (a Arg) Field(scope *ast.Scope) *ast.Field

func (Arg) Result

func (a Arg) Result() *ast.Field

type Iface

type Iface struct {
	Name, StubName, RcvrName *ast.Ident
	Methods                  []Method
	Prefix                   string
	Comments                 *ast.CommentGroup
}

func (Iface) Reciever

func (i Iface) Reciever() *ast.Field

func (Iface) StubStructDecl

func (i Iface) StubStructDecl(root *ast.File) ast.Decl

type Layouter

type Layouter interface {
	TransformAST(ctx *SourceContext, filedir ...string) error
}

type Method

type Method struct {
	Prefix          string
	Name            *ast.Ident
	Params          []Arg
	Results         []Arg
	Comments        []string
	StructsResolved bool
}

func (Method) FuncParams

func (m Method) FuncParams(scope *ast.Scope) *ast.FieldList

func (Method) FuncResults

func (m Method) FuncResults() *ast.FieldList

func (Method) RequestStruct

func (m Method) RequestStruct() ast.Decl

func (Method) RequestStructName

func (m Method) RequestStructName() (*ast.Ident, ast.Expr)

func (Method) ResponseStruct

func (m Method) ResponseStruct() ast.Decl

func (Method) ResponseStructFields

func (m Method) ResponseStructFields() *ast.FieldList

func (Method) ResponseStructName

func (m Method) ResponseStructName() *ast.Ident

func (Method) WrapRequest

func (m Method) WrapRequest() ast.Expr

type SourceContext

type SourceContext struct {
	Pkg        *ast.Ident
	Imports    []*ast.ImportSpec
	Interfaces []Iface
	Types      []*ast.TypeSpec
	Prefix     string
	Common     []*ast.Comment
}

func ParseFile

func ParseFile(source io.Reader, lay Layouter, outfiledir ...string) (*SourceContext, error)

func ParseFileByLayoutName

func ParseFileByLayoutName(source io.Reader, layname string, outfiledir ...string) (*SourceContext, error)

根据解析名称解析文件

func (*SourceContext) ImportDecls

func (sc *SourceContext) ImportDecls(root *ast.File) (decls []ast.Decl)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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