ast_parser

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ast_parser get type information from a package using go/ast

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name    string //字段名
	PkgPath string //包路径
	Type    string //类型

	CurrentTag string //main tag value

	Struct    *Struct
	Tag       reflect.StructTag //标签
	Private   bool              //私有
	Pointer   bool              //指针
	Slice     bool              //slice
	IsStruct  bool
	Docs      []string //上方文档注释
	Comment   string   //末尾的注释
	EnumValue any
	// contains filtered or unexported fields
}

func (*Field) GetTag

func (f *Field) GetTag(tag string) string

type File

type File struct {
	Name    string        //文件名
	Imports []*importItem //导入
	PkgPath string        //包路径
	Structs []*Struct     //结构体
	Docs    []string      //注释
}

File 文件

type Method

type Method struct {
	Receiver  *Receiver //接收器
	PkgPath   string    //包路径
	Name      string    //方法名称
	Private   bool
	Signature string //方法签名
	Docs      []string
	Params    []*Field //函数参数
	Results   []*Field //函数返回值
}

Method 结构体方法

type Parser

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

func NewParser

func NewParser(modPkg, modFile string) (p *Parser)

func (*Parser) Ignore

func (p *Parser) Ignore(importPath, t string)

Ignore a type by specified import path and type name

@param importPath
@param t type name

func (*Parser) Parse

func (p *Parser) Parse(pkg, s string) (f *File, err error)

Parse a type in a package

@param pkg package
@param s type name

@return error

func (*Parser) SetLogger

func (p *Parser) SetLogger(logger parser_logger.ParserLogger)

type Receiver

type Receiver struct {
	Name    string
	Pointer bool
	Type    string
}

Receiver 接收器

type Struct

type Struct struct {
	Name     string    //结构名称
	PkgPath  string    //包路径
	Fields   []*Field  //字段
	Methods  []*Method //方法
	Docs     []string  //上方文档注释
	IsEnum   bool
	EnumType string
}

Struct 结构体

func (*Struct) GetAllFieldsByTag

func (t *Struct) GetAllFieldsByTag(tag string) []*Field

Jump to

Keyboard shortcuts

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