goutil

package
v0.0.0-...-30c4fd9 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package goutil provides functions to work with Go source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(paths []string, mode build.ImportMode) ([]*build.Package, error)

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

func PredeclaredType(n string) bool

PredeclaredType reports if a type is a predeclared built-in type.

Note that this excludes composite types, such as maps, slices, channels, etc.

https://golang.org/ref/spec#Predeclared_identifiers

func ResolveImport

func ResolveImport(file, pkgName string) (string, error)

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

func ResolvePackage(path string, mode build.ImportMode) (pkg *build.Package, err error)

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

func ResolveWildcard(path string, mode build.ImportMode) ([]*build.Package, error)

ResolveWildcard finds all subpackages in the "example/..." format. The "/vendor/" directory will be ignored.

func TagName

func TagName(f *ast.Field, n string) string

TagName gets the tag name for a struct field with all attributes (like omitempty) removed. It will return the struct field name if there is no tag.

This function does not do any validation on the tag format. Use "go vet"!

Types

This section is empty.

Jump to

Keyboard shortcuts

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