Documentation ¶
Overview ¶
Package goutil provides functions to work with Go source files.
Index ¶
- func Expand(paths []string, mode build.ImportMode) ([]*build.Package, error)
- func ParseFiles(fset *token.FileSet, dir string, files []string, mode parser.Mode) (map[string]*ast.Package, error)
- func PredeclaredType(n string) bool
- func ResolveImport(file, pkgName string) (string, error)
- func ResolvePackage(path string, mode build.ImportMode) (pkg *build.Package, err error)
- func ResolveWildcard(path string, mode build.ImportMode) ([]*build.Package, error)
- func TagName(f *ast.Field, n string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Expand ¶
Expand a list of package and/or directory names to Go package names.
- "./example" is expanded to "full/package/path/example".
- "/absolute/src/package/path" is abbreviated to "package/path".
- "full/package" is kept-as is.
- "package/path/..." will include "package/path" and all subpackages.
The packages will be sorted with duplicate packages removed. The /vendor/ directory is automatically ignored.
func ParseFiles ¶
func ParseFiles( fset *token.FileSet, dir string, files []string, mode parser.Mode, ) (map[string]*ast.Package, error)
ParseFiles parses the given list of *.go files.
The advantage of this over parser.ParseDir() is that you can use the result of ResolvePackage() as input, which avoids a directory scan and takes build tags in to account (ParseDir() ignores any build tags).
func PredeclaredType ¶
PredeclaredType reports if a type is a predeclared built-in type.
Note that this excludes composite types, such as maps, slices, channels, etc.
func ResolveImport ¶
ResolveImport resolves an import name (e.g. "models") to the full imported package (e.g. "github.com/teamwork/desk/models") for a file. An empty string is returned if the package can't be resolved.
This will automatically keep a cache with name -> packagePath mappings to avoid having to parse the file more than once.
func ResolvePackage ¶
ResolvePackage resolves a package path, which can either be a local directory relative to the current dir (e.g. "./example"), a full path (e.g. ~/go/src/example"), or a package path (e.g. "example").
func ResolveWildcard ¶
ResolveWildcard finds all subpackages in the "example/..." format. The "/vendor/" directory will be ignored.
Types ¶
This section is empty.