Documentation ¶
Overview ¶
Package reflect is a wrapper for go/ast, go/token, and go/parser packages. It is used to get information about functions, methods, structures, and imports of go files in a specific directory.
Index ¶
- func AssertEqualArg(a1, a2 *Arg) error
- func AssertEqualArgs(as1, as2 Args) error
- func AssertEqualFunc(f1, f2 *Func) error
- func AssertEqualFuncs(fs1, fs2 Funcs) error
- func AssertEqualMethods(ms1, ms2 Methods) error
- func AssertEqualPkg(p1, p2 *Package) error
- func AssertEqualStruct(s1, s2 *Struct) error
- func AssertEqualStructs(ss1, ss2 Structs) error
- func AssertEqualType(t1, t2 *Type) error
- type Arg
- type Args
- type Comments
- type Func
- type Funcs
- type Imports
- type Methods
- type Package
- type Struct
- type Structs
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqualArg ¶
AssertEqualArg gets two *Arg parameters and returns nil in case they are equal and an error otherwise.
func AssertEqualArgs ¶
AssertEqualArgs gets two lists of arguments and returns nil if they are equal to each other and an error otherwise.
func AssertEqualFunc ¶
AssertEqualFunc returns nil if received functions are equal to each other and an error otherwise.
func AssertEqualFuncs ¶
AssertEqualFuncs returns nil if received function slices are equal to each other and an error otherwise.
func AssertEqualMethods ¶
AssertEqualMethods returns nil if received maps of methods are equal to each other and an error otherwise.
func AssertEqualPkg ¶
AssertEqualPkg makes sure two packages are equal to each other. If they are nil is returned. Otherwise, it returns an error.
func AssertEqualStruct ¶
AssertEqualStruct gets two *Struct arguments and makes sure they are equal. If they are a nil is returned. Otherwise, it will return an error.
func AssertEqualStructs ¶
AssertEqualStructs checks whether two slices of Structs are equal. If they are nil is returned. Otherwise, it will return an error.
func AssertEqualType ¶
AssertEqualType gets two *Type arguments and returns nil in case they are equal to each other and an error otherwise.
Types ¶
type Arg ¶
type Arg struct { Name string // Name of the argument, e.g. "name" or "age". Tag string // Tag is a field tag that may be presented. Type *Type // Type represents a type of argument. }
Arg is used to describe arguments of functions and fields of structures.
type Comments ¶
type Comments []string
Comments is a type that is used for representation of a comments list.
type Func ¶
type Func struct { Comments Comments // Comments that are located right above the function declaration. File string // Name of the file where the function is located. Name string // Name of the function, e.g. "Index" or "About". Params Args // A list of arguments this function receives. Recv *Arg // Receiver if it is a method and nil otherwise. Results Args // A list of arguments the function returns. }
Func is a type that represents information about a function or method.
type Funcs ¶
type Funcs []Func
Funcs is a type that represents a list of functions.
func (Funcs) FilterGroups ¶
FilterGroups gets a condition function and a number of group functions. It cuts off those Funcs that do not satisfy condition. And then groups the rest of them. For illustration:
res, count := myFuncs.Filter(isExported, withArguments, withoutArguments)
The result will be:
// All this functions are satisfying isExported condition. []Funcs{ Funcs{ these are functions withArguments }, Funcs{ these are functions withoutArguments }, }
type Imports ¶
Imports is a map of import paths in the following format:
- Filename:
- Import name:
- Import value
func (Imports) Name ¶
Name checks whether an import that ends with a requested value exists in the requested file. If so, it's name and true are returned. Otherwise, empty string and false will be the results. Imports are ensured to end with the value rather than be equal to it for compatibility with "vendor" package manager.
type Methods ¶
Methods is a map of functions with receiver in the following format:
- Name of a struct:
- Methods
type Package ¶
type Package struct { Funcs Funcs // A list of functions of the package. Imports Imports // Imports of this package grouped by files. Methods Methods // Struct names and their Methods (functions with receivers). Name string // Name of the package, e.g. "controllers". Structs Structs // A list of struct types of the package. }
Package is a type that combines declarations of functions, types, and structs of a single go package.
type Struct ¶
type Struct struct { Comments Comments // Comments right above the struct declaration. Fields Args // A list of fields that belong to this struct. File string // Name of the file where the function is located. Name string // Name of the struct, e.g. "Application". }
Struct is a type that represents information about a specific struct, its fields, and comments group.