goast

package
v0.0.0-...-dbf91d7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewParseAll

func NewParseAll() *parseAll

func SaveGoMeta

func SaveGoMeta(key string, meta *GoMeta)

Types

type Def

type Def struct {
	// Name 是 `type Tag struct{}` 中的 Tag
	Name string
	// Key 是 唯一标识. e.g. github.com/gopenapi/gopenapi/internal/model.Tag
	Key  string
	Type ast.Expr `json:"-"`

	// 只有方法定义有这个值
	FuncRecv *ast.FieldList `json:"-"`
	// 定义在哪个文件(相对路径), e.g. github.com/gopenapi/gopenapi/internal/model/pet.go
	File string
	Doc  *ast.CommentGroup
}

所有的定义

方法
类型

type Enum

type Enum struct {
	Type   string        `json:"type"`
	Values []interface{} `json:"values"`
	Keys   []string      `json:"keys"`
}

func (*Enum) FirstValue

func (e *Enum) FirstValue() (string, interface{})

FirstValue 返回第一个枚举值, 一般用作default值.

type GoMeta

type GoMeta struct {
}

type GoParse

type GoParse struct {
	// contains filtered or unexported fields
}

GoParse Parse the go src to: - doc - struct

func NewGoParse

func NewGoParse(gosrc *gosrc.GoSrc) *GoParse

func (*GoParse) FormatPath

func (g *GoParse) FormatPath(path string) (fp string, isInProject bool)

func (*GoParse) GetDef

func (g *GoParse) GetDef(pkgDir string, key string) (def *Def, exist bool, err error)

GetDef 获取结构体/方法定义 pkgDir: 基于gomod的引入路径 key:

PetHandler
or: PetHandler.FuncA
不支持查询结构体成员属性.

func (*GoParse) GetEnum

func (g *GoParse) GetEnum(pkgDir string, typ string) (enum *Enum, err error)

GetEnum 获取枚举值, 只支持基础类型.

func (*GoParse) GetFileImportedPkgs

func (g *GoParse) GetFileImportedPkgs(filePath string) (pkgs Pkgs, err error)

GetFileImportedPkgs 获取文件中所有导入的包. Tips: 目前只支持获取文件中导入的**本项目**的其他包. goFilePath: github.com/gopenapi/gopenapi/internal/delivery/http/handler/pet.go

func (*GoParse) GetFuncOfStruct

func (g *GoParse) GetFuncOfStruct(pkgDir string, typName string) (enum map[string]*Def, err error)

GetFuncOfStruct 获取结构体上的func

func (*GoParse) GetPkgOfFile

func (g *GoParse) GetPkgOfFile(filePath string) (pkg string)

GetPkgOfFile 获取文件所在的pkg github.com/gopenapi/gopenapi/internal/delivery/http/handler/pet.go 返回 github.com/gopenapi/gopenapi/internal/delivery/http/handler

type Let

type Let struct {
	Value interface{}
	Type  ast.Expr
	Name  string
	// 定义在哪个文件
	File string
	Doc  *ast.CommentGroup
}

变量以及常量

type Pkg

type Pkg struct {
	// 包源代码地址
	Dir string
	// 包名
	PkgName string
}

type Pkgs

type Pkgs map[string]*Pkg

Pkgs key: 导入的名字, 如别名 和 ., value: 包信息 暂时不支持.的处理

Jump to

Keyboard shortcuts

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