Documentation ¶
Overview ¶
Package pkg 用于对包的解析管理
Index ¶
- Constants
- type Named
- type NotFound
- type NotImplement
- type Packages
- func (pkgs *Packages) FileSet() *token.FileSet
- func (pkgs *Packages) Package(path string) *packages.Package
- func (pkgs *Packages) Range(f func(*packages.Package) bool)
- func (pkgs *Packages) ScanDir(ctx context.Context, root string, recursive bool)
- func (pkgs *Packages) TypeOf(ctx context.Context, path string) (types.Type, error)
- type Struct
Constants ¶
View Source
const Cancelled = web.StringPhrase("cancelled")
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Named ¶
Named 这是对 types.Named 的二次包装
type NotFound ¶
type NotFound string
NotFound 表示该类型不存在时返回此类型
一般情况下是引用了未导入的类型,比如:type T = web.State 如果 web 包未被导入,那么 web.State 将会变成 NotFound 类型。
func (NotFound) Underlying ¶
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 (*Packages) TypeOf ¶
TypeOf 查找名为 path 的相关类型信息
path 为完整的类型名,需要包含路径部分。完整格式如下:
[prefix][path.]type[[type param]][<fields>]
其中 prefix 表示类型修改的前缀,可以有以下三种格式:
- [] 表示数组;
- * 表示指针;
- [x] 数组,x 必须得是正整数;
path 表示类型的包路径,如果是非内置类型,该值是必须的; type param 表示泛型的实参,比如 [int, float] 等; fields 用于指定替换 type 中的字段,格式为:<field=typePath>; path 拥有以下两个特殊值:
- {} 表示空值,将返回 nil, true
- map 或是 any 将返回 types.InterfaceType
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct 这是对 types.Struct 的包装
func (*Struct) Underlying ¶
Click to show internal directories.
Click to hide internal directories.