Importing with Vendoring in Go 1.6
Despite extensive documentation and community assistance, importing using the vendor feature in Go 1.6 has proven elusive for some.
Question:
A developer struggled to import using the vendor feature with a sample project structured as follows:
Directory Structure:
. └── src ├── main.go └── vendor └── github.com └── zenazn └── goji ├── LICENSE ├── README.md ├── bind ├── default.go ├── example ├── goji.go ├── graceful ├── serve.go ├── serve_appengine.go └── web
Main.go:
package main import ( "fmt" "net/http" "github.com/zenazn/goji" "github.com/zenazn/goji/web" ) func hello(c web.C, w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"]) } func main() { goji.Get("/hello/:name", hello) goji.Serve() }
Environment Variables:
export GOPATH=~/.go export GOBIN=$GOPATH/bin export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOBIN
Answer:
A fundamental understanding of how Go tools handle source code and GOPATH is crucial. Here's how to import with vendoring:
The above is the detailed content of Why is Importing with Vendoring in Go 1.6 Difficult for Some?. For more information, please follow other related articles on the PHP Chinese website!