Avoid deprecated LoadModes packages.{LoadFiles, LoadSyntax} (#116)

From the docs for packages.{LoadFiles, LoadSyntax} -
https://godoc.org/golang.org/x/tools/go/packages#pkg-constants

	// Deprecated: LoadFiles exists for historical compatibility
	// and should not be used. Please directly specify the needed
	// fields using the Need values.
	// ...
	// Deprecated: LoadSyntax exists for historical compatibility
	// and should not be used. Please directly specify the needed
	// fields using the Need values.
This commit is contained in:
Suhas Karanth 2020-01-17 10:25:50 +05:30 committed by GitHub
parent 75d0ddfc00
commit 8f50fb6793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ _testmain.go
*.test
*.prof
.vscode
.idea

View File

@ -71,7 +71,7 @@ type Mocker struct {
// New makes a new Mocker for the specified package directory.
func New(src, packageName string) (*Mocker, error) {
srcPkg, err := pkgInfoFromPath(src, packages.LoadSyntax)
srcPkg, err := pkgInfoFromPath(src, packages.NeedName|packages.NeedTypes|packages.NeedTypesInfo)
if err != nil {
return nil, fmt.Errorf("couldn't load source package: %s", err)
}
@ -118,7 +118,7 @@ func findPkgPath(pkgInputVal string, srcPkg *packages.Package) (string, error) {
}
func pkgInDir(pkgName, dir string) bool {
currentPkg, err := pkgInfoFromPath(dir, packages.LoadFiles)
currentPkg, err := pkgInfoFromPath(dir, packages.NeedName)
if err != nil {
return false
}