From ccaa079f7c6362407f69bd2e46aeb88eebcc9ca1 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 28 Mar 2020 09:15:08 -0700 Subject: [PATCH] Using pacakges.NeedName (#418) packages.LoadFiles is deprecated. It is not future-proof to use it. In addition, I found all mockgen need is Package.PkgPath, so packages.NeedName is sufficient. --- mockgen/parse.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mockgen/parse.go b/mockgen/parse.go index a8edde80..7f1a433c 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -548,7 +548,11 @@ func packageNameOfDir(srcDir string) (string, error) { // parseImportPackage get package import path via source file func parsePackageImport(source, srcDir string) (string, error) { - cfg := &packages.Config{Mode: packages.LoadFiles, Tests: true, Dir: srcDir} + cfg := &packages.Config{ + Mode: packages.NeedName, + Tests: true, + Dir: srcDir, + } pkgs, err := packages.Load(cfg, "file="+source) if err != nil { return "", err