Import package by files if outside of GOPATH
This is for example the case, if a mock is generated for an external interface while go modules are enabled. Fixes: #79
This commit is contained in:
parent
c4521bcc9d
commit
d95e87fb17
@ -10,6 +10,7 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -234,7 +235,19 @@ func pkgInfoFromPath(src string) (*loader.PackageInfo, error) {
|
|||||||
ParserMode: parser.SpuriousErrors,
|
ParserMode: parser.SpuriousErrors,
|
||||||
Cwd: src,
|
Cwd: src,
|
||||||
}
|
}
|
||||||
conf.Import(pkgFull)
|
if strings.HasPrefix(pkgFull, string(filepath.Separator)) {
|
||||||
|
files, err := ioutil.ReadDir(pkgFull)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if !file.IsDir() && strings.HasSuffix(file.Name(), ".go") && !strings.HasSuffix(file.Name(), "_test.go") {
|
||||||
|
conf.CreateFromFilenames(abs, file.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
conf.Import(pkgFull)
|
||||||
|
}
|
||||||
lprog, err := conf.Load()
|
lprog, err := conf.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user