srcdom

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 14 Imported by: 2

README

koron-go/srcdom

PkgGoDev Actions/Go Go Report Card

Documentation

Overview

Package srcdom provides utilities to manipulate Go's AST (Abstract Structure Tree). Using srcdom, you can easily access/extract information of types, funcions and variables from AST.

Index

Constants

This section is empty.

Variables

View Source
var WarnLog = log.New(os.Stderr, "srcdom:warn ", log.LstdFlags)

WarnLog is log destination for warning messages

Functions

This section is empty.

Types

type Field

type Field struct {
	Name string
	Type string
	Tag  *Tag
}

Field represents a variable.

type Func

type Func struct {
	Name    string
	Params  []*Var
	Results []*Var
}

Func represents a function.

func (*Func) IsPublic

func (fn *Func) IsPublic() bool

IsPublic checks its name is public or not.

type Import

type Import struct {
	Name string
	Path string
}

Import represents an import.

type Package

type Package struct {
	Name string

	Imports []*Import

	Values []*Value

	Funcs []*Func

	Types []*Type
	// contains filtered or unexported fields
}

Package represents a go package.

func Read

func Read(path string) (*Package, error)

Read reads a file or directory as a Package. If you are going to read a directory, see also ReadDir.

func ReadDir added in v0.2.0

func ReadDir(path string, testPackage bool) (*Package, error)

ReadDir reads a directory as a Package. It reads "test" package when `testPackage` is set. It will fail if the directory contains non-test multiple packages.

func (*Package) Func

func (p *Package) Func(name string) (*Func, bool)

Func gets a func which matches with name.

func (*Package) FuncNames added in v0.3.0

func (p *Package) FuncNames() []string

FuncNames returns sorted names of function in the package.

func (*Package) Type

func (p *Package) Type(name string) (*Type, bool)

Type gets a type which matches with name.

func (*Package) TypeNames added in v0.3.0

func (p *Package) TypeNames() []string

TypeNames returns sorted names of type in the package.

func (*Package) Value added in v0.3.0

func (p *Package) Value(name string) (*Value, bool)

Value gets a value which matches with name.

func (*Package) ValueNames added in v0.3.0

func (p *Package) ValueNames() []string

ValueName returns sorted names of value in the package.

type Parser

type Parser struct {
	Package *Package
}

Parser is a parser for go source files.

func (*Parser) ScanFile

func (p *Parser) ScanFile(file *ast.File) error

ScanFile scans a ast.File to build Package.

type Tag

type Tag struct {
	Raw string

	Values []*TagValue
	// contains filtered or unexported fields
}

Tag represents a tag for field

func (*Tag) TagValue

func (tag *Tag) TagValue(n string) (*TagValue, bool)

TagValue gets a tag value which matches with name.

type TagValue

type TagValue struct {
	Name   string
	Raw    string
	Values []string
}

TagValue represents content of a tag.

type Type

type Type struct {
	Name    string
	Defined bool

	IsStruct    bool
	IsInterface bool

	Embeds []string

	Fields []*Field

	Methods []*Func
	// contains filtered or unexported fields
}

Type represents a function.

func (*Type) Embed

func (typ *Type) Embed(n string) bool

Embed checks the type has embed type or not.

func (*Type) Field

func (typ *Type) Field(n string) (*Field, bool)

Field gets a field which matches with name.

func (*Type) FieldsByTag

func (typ *Type) FieldsByTag(tagQuery string) []*Field

FieldsByTag collects fields which match with query. The query's format is "{tagName}" or "{tagName}:{value}".

func (*Type) IsPublic

func (typ *Type) IsPublic() bool

IsPublic checks its name is public or not.

func (*Type) Method

func (typ *Type) Method(n string) (*Func, bool)

Method gets a method Func which matches with name.

type Value

type Value struct {
	Name    string
	Type    string
	IsConst bool

	Literal *ast.BasicLit
}

Value represents a value or const

func (*Value) IsPublic

func (v *Value) IsPublic() bool

IsPublic checks its name is public or not.

type Var

type Var struct {
	Name string
	Type string
}

Var represents a variable.

Jump to

Keyboard shortcuts

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