Documentation ¶
Overview ¶
package search is used to find targets for the generator.
Index ¶
- func FindConstantsByType(pkgpath, name string, a *AST) (consts []*types.Const)
- func FindFunc(pkgpath, name string, a *AST) (fn *types.Func, rawCfg []byte, err error)
- func FindIncludedFuncs(a *AST, callback func(fn *types.Func, rawCfg []byte) error) error
- func FindObject(pkgpath, name string, a *AST) (obj types.Object, err error)
- type AST
- type Error
- type ErrorCode
- type File
- type Match
- type Package
- type Pkg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindConstantsByType ¶
FindConstantsByType scans the given AST looking for all declared constants of the type identified by pkgpath and name. On success the result will be a slice of go/types.Const instances that represent those constants.
FindConstantsByType is exepcted to be invoked *after* Search and the AST argument is expected to be the same as the one given to Search for caching the packages it loads.
func FindFunc ¶
FindFunc scans the package identified by pkgpath looking for a function with the given name and, if successful, returns the go/types.Func representation of that function.
FindFunc is exepcted to be invoked *after* Search and the AST argument is expected to be the same as the one given to Search for caching the packages it loads.
The pkgpath parameter should be the import path of a single package, if it's a pattern or something else then the result is undefined.
func FindIncludedFuncs ¶ added in v1.2.1
FindIncludedFuncs
TODO(mkopriva): make this not blow up if package can't be found
on the system, because of the following: It is possible that the user of the cmd/validgen tool does not have github.com/frk/valid source on the user's machine, which is ok because the source would be downloaded automatically as soon as the user attempts to run the generated code, or maybe the user does not intend to use the included rules, or perhaps the user has supplied a set of custom rules that override the included ones anyway. In case the error is genuine the code should keep working without issues, it's just that the reporting of user errors will be poorer.
Types ¶
type AST ¶
type AST struct {
// contains filtered or unexported fields
}
AST is used to hold the packages that were loaded during a call to Search.
type Error ¶
type Error struct { C ErrorCode // contains filtered or unexported fields }
func (*Error) OriginalError ¶
type ErrorCode ¶
type ErrorCode uint
const ( ERR_OBJECT_NOTFOUND ErrorCode // object (func or type) not found ERR_FUNC_NOTFOUND // func not found ERR_PKG_NOTFOUND // package not found ERR_PKG_LOADFAIL // failed loading package ERR_PKG_ERROR // package contains errors )
type Match ¶
type Match struct { // The go/types.Named representation of the matched type. Named *types.Named `cmp:"+"` // The file set with which the matched type is associated. Fset *token.FileSet `cmp:"+"` // The source position of the matched type. Pos token.Pos `cmp:"+"` }
Match holds information on a matched validator struct type.
type Package ¶
type Package struct { Name string Path string Fset *token.FileSet `cmp:"+"` Type *types.Package `cmp:"+"` Info *types.Info `cmp:"+"` Files []*File }
Package represents a Go package that contains one or more matching validator struct types.
func Search ¶
func Search(dir string, recursive bool, rxValidator *regexp.Regexp, filter func(filePath string) bool, a *AST) (out []*Package, err error)
Search scans one or more Go packages looking for validator struct types whose names match the rxValidator regexp. The result will be a list of Packages, where each Package will contain a list of Files that belong to that Package, and each of these Files will contain a list of Matches each representing a validator struct type declared in that File.
Scanned files and packages that do not contain any matching validator struct type declarations will be omitted from the result.
Search will scan the Go package that is located in the specified directory and, optionally, if recursive is true, it will also scan the packages located in the hierarchy of the specified directory.
If the *AST argument is not nil it will be populated with the list of packages that were loaded from the specified directory.