dongyong2906 2016-03-14 22:09
浏览 25
已采纳

Go 1.6中的供应商

I’ve read as many docs and StackOverflow articles as I can find, yet I am having no luck importing using the new vendor feature in Go 1.6.

Here's a sample project I put together with Goji to test. The directory structure is as such:

.
└── src
    ├── main.go
    └── vendor
        └── github.com
            └── zenazn
                └── goji
                    ├── LICENSE
                    ├── README.md
                    ├── bind
                    ├── default.go
                    ├── example
                    ├── goji.go
                    ├── graceful
                    ├── serve.go
                    ├── serve_appengine.go
                    └── web

And main.go, the sole file in the project, is as such:

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()
}

My environment variables are as such:

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

I’ve tried the most simple build commands, with no luck:

go run ./src/main.go
go build ./src/main.go

I’ve also attempted to build with:

$GOPATH=`pwd`

...to no avail. Am I totally missing something? Any advice is appreciated.

  • 写回答

1条回答 默认 最新

  • doujianwan7570 2016-03-16 01:15
    关注

    I suggest you to read https://golang.org/doc/code.html. It requires a day or two to digest but after you understand how go tools work with the source code and GOPATH it is really easy to use them.

    Back to your question. To build a simple go program you need to:

    • create directory under $GOPATH/src, e.g. mkdir $GOPATH/src/myprogram
    • put all the source code (including vendor directory) there: $GOPATH/src/myprogram/main.go, $GOPATH/src/myprogram/vendor.
    • run go install myprogram to build your application and put the resulting myprogram binary to $GOPATH/bin/myprogram
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)