在Go 1.6中供应 [英] Vendoring in Go 1.6

查看:65
本文介绍了在Go 1.6中供应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读尽可能多的文档和StackOverflow文章,但我没有运用Go 1.6中的新供应商功能导入。



这里是我使用 Goji 进行测试的示例项目。目录结构是这样的:

 
└──src
├──main.go
└──卖方
└──github.com
└──zenazn
└─ ─goji
├──LICENSE
├──README.md
├──bind
├──default.go
├──示例
├──goji.go
├──优雅
├──serve.go
├──serve_appengine.go
└──web

$ b

main.go ,这个项目中唯一的文件就是这样的:

 软件包主要

导入(
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,Hel (/ hello /:name,%s!,c.URLParams [name])
}

func main(){
goji.Get hello)
goji.Serve()
}

我的环境变量为例如:

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



已经尝试了最简单的构建命令,没有运气:

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

我也试图用以下方式构建:

  $ GOPATH =`pwd` 

...无济于事。我完全错过了什么吗?任何建议表示赞赏。

解决方案

我建议您阅读 https://golang.org/doc/code.html 。它需要一到两天的时间才能消化,但是在了解了工具如何与源代码和GOPATH配合使用后,使用它们非常简单。



返回到您的问题。要创建一个简单的go程序,您需要:


  • 在$ GOPATH / src下创建目录,例如 mkdir $ GOPATH / src / myprogram

  • 放置所有源代码(包括供应商目录): $
  • 运行去安装myprogram 来构建您的应用程序,并将生成的 myprogram 二进制文件放到 $ GOPATH / bin / myprogram


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.

解决方案

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

这篇关于在Go 1.6中供应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆