Golang go/build.Context.Import() function examples
package go/build
Import returns details about the Go package named by the import path, interpreting local import paths relative to the srcDir directory. If the path is a local import path naming a package that can be imported using a standard import path, the returned package will set p.ImportPath to that path.
In the directory containing the package, .go, .c, .h, and .s files are considered part of the package except for:
.go files in package documentation
files starting with _ or . (likely editor temporary files)
files with build constraints not satisfied by the context
If an error occurs, Import returns a non-nil error and a non-nil *Package containing partial information.
Golang go/build.Context.Import() function usage examples
Example 1:
pkg, err = build.Default.Import(name, ".", build.ImportMode(1))
Example 2:
func packageWithName(name string) (pkg *build.Package, err error) {
pkg, err = build.Default.Import(name, ".", build.ImportMode(0))
if err == nil {
return
}
pkg, err = build.Default.Import(name, ".", build.ImportMode(1))
return
}
References :
https://github.com/onsi/ginkgo/blob/master/ginkgo/convert/package_rewriter.go
Advertisement
Something interesting
Tutorials
+6.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+21.1k Golang : Convert(cast) string to rune and back to string example
+9.7k Golang : Detect number of active displays and the display's resolution
+11.4k Golang : Concatenate (combine) buffer data example
+5.6k Javascript : How to refresh page with JQuery ?
+11.6k Golang : Concurrency and goroutine example
+14k Golang : Google Drive API upload and rename example
+17.5k Golang : Linked list example
+6.9k Golang : Fibonacci number generator examples
+39.6k Golang : Remove dashes(or any character) from string
+11k How to test Facebook App on localhost ?
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine