Golang 1.5供应商 – 找不到包

huangapple go评论76阅读模式
英文:

Golang 1.5 vendors - Cannot find package

问题

尝试使用Go语言版本1.5构建我的项目,打开GO15VENDOREXPERIMENT="1"以确保在本地查找供应商。

我的项目结构如下:

apps_api
   main.go
   build.sh
   src
      controllers
      models
      views
   vendor
      github.com
      golang.org
      .....

build.sh文件内容如下:

export GO15VENDOREXPERIMENT="1"
export GOPATH=`pwd`
go build .

控制器文件示例:

import (
    "models"
    "views"

    "github.com/gin-gonic/gin"
)

但是我遇到了很多错误,显示找不到包,请参见下面的示例:

src/controllers/app-versions.go:10:2: cannot find package "github.com/asaskevich/govalidator" in any of:
	/Users/ereeve/.gvm/gos/go1.5/src/github.com/asaskevich/govalidator (from $GOROOT)
	/Users/ereeve/Documents/gocode/src/apps_api/src/github.com/asaskevich/govalidator (from $GOPATH)

src/controllers/index.go:4:2: cannot find package "github.com/chnlr/baseurl" in any of:
    /Users/ereeve/.gvm/gos/go1.5/src/github.com/chnlr/baseurl (from $GOROOT)
    /Users/ereeve/Documents/gocode/src/apps_api/src/github.com/chnlr/baseurl (from $GOPATH)

如果我将这些行添加到我的build.sh文件中,它将构建成功,但是我不想使用go get,因为我正在使用带有本地供应商的go 1.5来避免依赖项。

# go get github.com/gin-gonic/gin
# go get github.com/go-sql-driver/mysql
# go get github.com/rif/cache2go
....

有任何想法我做错了什么吗?

英文:

Trying to build my project in go lang using version 1.5 with GO15VENDOREXPERIMENT="1" turned on to ensure I look for the vendors locally.

My structure is:

apps_api
   main.go
   build.sh
   src
      controllers
      models
      views
   vendor
      github.com
      golang.org
      .....

build.sh contains

export GO15VENDOREXPERIMENT="1"
export GOPATH=`pwd`
go build .

controller file example

import (
    "models"
    "views"

    "github.com/gin-gonic/gin"
)

But i get lots of errors saying package not found see below for exmaple

src/controllers/app-versions.go:10:2: cannot find package "github.com/asaskevich/govalidator" in any of:
	/Users/ereeve/.gvm/gos/go1.5/src/github.com/asaskevich/govalidator (from $GOROOT)
	/Users/ereeve/Documents/gocode/src/apps_api/src/github.com/asaskevich/govalidator (from $GOPATH)

src/controllers/index.go:4:2: cannot find package "github.com/chnlr/baseurl" in any of:
    /Users/ereeve/.gvm/gos/go1.5/src/github.com/chnlr/baseurl (from $GOROOT)
    /Users/ereeve/Documents/gocode/src/apps_api/src/github.com/chnlr/baseurl (from $GOPATH)

If i add these lines into my build.sh file it will build, but I don't want to use go get because I am using go 1.5 with the vendors locally inside my project to avoid dependancies.

# go get github.com/gin-gonic/gin
# go get github.com/go-sql-driver/mysql
# go get github.com/rif/cache2go
....

Any ideas what I am doing wrong?

答案1

得分: 9

如果我没记错的话,GO15VENDOREXPERIMENT 只会在你构建的包位于 $GOPATH/src 目录下时才起作用,所以在你的 build.sh 中设置

export GOPATH=`pwd`

会导致它失败。如果你将你的 apps_api 放在 ~/fakegopath/src/ 目录下,并运行

env GOPATH="${HOME}/fakegopath/src/" GO15VENDOREXPERIMENT="1" go build .

它应该可以工作。

英文:

IIRC, GO15VENDOREXPERIMENT will work only if the package you're building is inside $GOPATH/src, so setting

export GOPATH=`pwd`

in your build.sh makes it fail. If you put your apps_api inside say ~/fakegopath/src/ and run

env GOPATH="${HOME}/fakegopath/src/" GO15VENDOREXPERIMENT="1" go build .

it should work.

huangapple
  • 本文由 发表于 2015年10月9日 17:17:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/33034442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定