wide/vendor/github.com/visualfc/gotools/stdlib/go14.go

20 lines
435 B
Go

// +build go1.4
package stdlib
import (
"go/build"
"os"
"path/filepath"
)
func ImportStdPkg(context *build.Context, path string, mode build.ImportMode) (*build.Package, error) {
realpath := filepath.Join(context.GOROOT, "src", path)
if _, err := os.Stat(realpath); err != nil {
realpath = filepath.Join(context.GOROOT, "src/pkg", path)
}
pkg, err := context.ImportDir(realpath, 0)
pkg.ImportPath = path
return pkg, err
}