Why is Importing with Vendoring in Go 1.6 Difficult for Some?

DDD
Release: 2024-10-28 22:38:30
Original
953 people have browsed it

Why is Importing with Vendoring in Go 1.6 Difficult for Some?

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
Copy after login

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()
}
Copy after login

Environment Variables:

export GOPATH=~/.go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOBIN
Copy after login

Answer:

A fundamental understanding of how Go tools handle source code and GOPATH is crucial. Here's how to import with vendoring:

  • Create a directory under $GOPATH/src, e.g.: mkdir $GOPATH/src/myprogram
  • Place the source code and vendor directory within the created directory: $GOPATH/src/myprogram/main.go and $GOPATH/src/myprogram/vendor
  • Execute go install myprogram to build the application and place the binary in $GOPATH/bin/myprogram

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!