gadget

package
v0.0.0-...-2bde968 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	String  = Ident("string")
	Bool    = Ident("bool")
	Byte    = Ident("byte")
	Rune    = Ident("rune")
	Uintptr = Ident("uintptr")

	Int   = Ident("int")
	Int8  = Ident("int8")
	Int16 = Ident("int16")
	Int32 = Ident("int32")
	Int64 = Ident("int64")

	Uint   = Ident("uint")
	Uint8  = Ident("uint8")
	Uint16 = Ident("uint16")
	Uint32 = Ident("uint32")
	Uint64 = Ident("uint64")

	Float32    = Ident("float32")
	Float64    = Ident("float64")
	Complex64  = Ident("complex64")
	Complex128 = Ident("complex128")

	EmptyStruct = Struct{}
	Bytes       = Slice{Elem: Byte}
	Error       = Ident("error")
)

Functions

func SameType

func SameType(t, t2 Type) bool

SameType will return true if the given types are the same.

func TypeIs

func TypeIs(t Type, s string) bool

TypeIs checks if the given type is equal to the type defined in the given string, as parsed by ParseType.

Types

type Array

type Array struct {
	Elem Type
	Size int
}

func (Array) String

func (a Array) String() string

type Chan

type Chan struct {
	Dir  ChanDir
	Elem Type
}

func (Chan) String

func (c Chan) String() string

type ChanDir

type ChanDir int

ChanDir represents the direction of a channel type

const (
	SEND ChanDir = iota
	RECV
	BOTH
)

func (ChanDir) String

func (d ChanDir) String() string

type File

type File struct {
	Path      string       // The path of the Go file this File represents.
	Imports   []ImportDecl // The imports contained within the Go file.
	Types     []TypeDecl   // The Type declarations contained within the Go file.
	Funcs     []FuncDecl   // The Function declarations contained within the Go file.
	HasErrors bool         // HasErrors is true if there was an invalid declaration was found.
}

File contains all the information we have about a parsed Go file.

func NewFile

func NewFile(path string, reader io.Reader) (*File, error)

NewFile parses a Go file. If reader is nil, the file at path is opened. Otherwise, reader is taken to be the contents of the file.

func (*File) GetMethods

func (f *File) GetMethods(typeName string) map[string]Func

GetMethods fetches the methods belonging to the given type identifier.

func (*File) GetTypes

func (f *File) GetTypes() map[string]Type

GetTypes fetches all non-alias types.

type Func

type Func struct {
	Params  []FuncParam
	Results []FuncResult
}

func (Func) String

func (f Func) String() string

type FuncDecl

type FuncDecl struct {
	Position
	Name string // The function name.
	Recv string // The receiver type identifier.
	Type Func   // The function type.
}

type FuncParam

type FuncParam struct {
	Name string
	Type Type
}

func (FuncParam) String

func (f FuncParam) String() string

type FuncResult

type FuncResult struct {
	Name string
	Type Type
}

func (FuncResult) String

func (f FuncResult) String() string

type Ident

type Ident string

func (Ident) String

func (i Ident) String() string

type ImportDecl

type ImportDecl struct {
	Position
	Name string // The identifier of the import decl (can be empty "." or "_")
	Path string // The import path.
}

type Info

type Info struct {
	Arch    string
	OS      string
	Package string
	File    string
	Line    int
	// contains filtered or unexported fields
}

Info contains the information about a go generate call.

func Generate

func Generate() (*Info, error)

Generate returns the information about the current go generate call. It will return an error if this execution was not apparently initiated by go generate.

func (*Info) GetType

func (i *Info) GetType() (string, Type, error)

GetType returns the name and type of the type selected to generate for. If we could not find the type we are generating for, GetType returns an error.

func (*Info) Open

func (i *Info) Open() (*File, error)

Open will open the file the Info refers to.

type Interface

type Interface struct {
	Methods []InterfaceMethod
}

func (Interface) String

func (i Interface) String() string

type InterfaceMethod

type InterfaceMethod struct {
	Name string
	Type Func
}

func (InterfaceMethod) String

func (f InterfaceMethod) String() string

type Map

type Map struct {
	Key   Type
	Value Type
}

func (Map) String

func (m Map) String() string

type Pointer

type Pointer struct {
	Elem Type
}

func (Pointer) String

func (p Pointer) String() string

type Position

type Position struct {
	Path string
	Line int
}

Position represents a file:line location.

func (Position) String

func (pos Position) String() string

type Selector

type Selector struct {
	Left  Ident
	Right Ident
}

func (Selector) String

func (s Selector) String() string

type Slice

type Slice struct {
	Elem Type
}

func (Slice) String

func (s Slice) String() string

type Struct

type Struct struct {
	Fields []StructField
}

func (Struct) String

func (s Struct) String() string

type StructField

type StructField struct {
	Name string
	Type Type
	Tag  string
}

func (StructField) String

func (f StructField) String() string

type Type

type Type interface {
	String() string
	// contains filtered or unexported methods
}

Type is one of the following concrete types: Ident, Pointer, Slice, Array, Map, Struct, Chan, Func, Interface, Selector

func ParseType

func ParseType(s string) (Type, error)

ParseType takes a string containing a Go type definition, and returns the Type.

type TypeDecl

type TypeDecl struct {
	Position
	Name  string // The type name.
	Type  Type   // The actual type definition. May be empty if the type declaration is an alias.
	Alias Type   // The alias this declaration references. May be nil if the type declaration is not an alias. Is either Ident or Selector.
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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