pkg

package
v0.0.0-...-07eafe9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package pkg 用于对包的解析管理

Index

Constants

View Source
const Cancelled = web.StringPhrase("cancelled")

Variables

This section is empty.

Functions

This section is empty.

Types

type Named

type Named struct {
	*types.Named
	// contains filtered or unexported fields
}

Named 这是对 types.Named 的二次包装

func (*Named) Doc

func (n *Named) Doc() *ast.CommentGroup

Doc 关联的文档内容

func (*Named) ID

func (n *Named) ID() string

ID 当前对象的唯一名称

func (*Named) Next

func (n *Named) Next() types.Type

Next 指向的类型

func (*Named) TypeArgs

func (n *Named) TypeArgs() typeList

type NotFound

type NotFound string

NotFound 表示该类型不存在时返回此类型

一般情况下是引用了未导入的类型,比如:type T = web.State 如果 web 包未被导入,那么 web.State 将会变成 NotFound 类型。

func (NotFound) String

func (t NotFound) String() string

func (NotFound) Underlying

func (t NotFound) Underlying() types.Type

type NotImplement

type NotImplement string

NotImplement 一些未实现的类型

比如 interface{} 作为字段类型时,将返回该对象。

func (NotImplement) String

func (t NotImplement) String() string

func (NotImplement) Underlying

func (t NotImplement) Underlying() types.Type

type Packages

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

Packages 管理加载的包

func New

func New(l *logger.Logger) *Packages

func (*Packages) FileSet

func (pkgs *Packages) FileSet() *token.FileSet

func (*Packages) Package

func (pkgs *Packages) Package(path string) *packages.Package

Package 返回指定路径的包对象

func (*Packages) Range

func (pkgs *Packages) Range(f func(*packages.Package) bool)

Range 依次访问已经加载的包

f 如果返回了 false,将退出循环

func (*Packages) ScanDir

func (pkgs *Packages) ScanDir(ctx context.Context, root string, recursive bool)

ScanDir 添加 root 下的内容

root 添加的目录;

func (*Packages) TypeOf

func (pkgs *Packages) TypeOf(ctx context.Context, path string) (types.Type, error)

TypeOf 查找名为 path 的相关类型信息

path 为完整的类型名,需要包含路径部分。完整格式如下:

[prefix][path.]type[[type param]][<fields>]

其中 prefix 表示类型修改的前缀,可以有以下三种格式:

  • [] 表示数组;
  • * 表示指针;
  • [x] 数组,x 必须得是正整数;

path 表示类型的包路径,如果是非内置类型,该值是必须的; type param 表示泛型的实参,比如 [int, float] 等; fields 用于指定替换 type 中的字段,格式为:<field=typePath>; path 拥有以下两个特殊值:

type Struct

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

Struct 这是对 types.Struct 的包装

func (*Struct) Field

func (s *Struct) Field(i int) *types.Var

func (*Struct) FieldDoc

func (s *Struct) FieldDoc(i int) *ast.CommentGroup

FieldDoc 第 i 个元素的文档

func (*Struct) NumFields

func (s *Struct) NumFields() int

func (*Struct) String

func (s *Struct) String() string

func (*Struct) Tag

func (s *Struct) Tag(i int) string

func (*Struct) Underlying

func (s *Struct) Underlying() types.Type

Jump to

Keyboard shortcuts

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