如何向 godep.json 添加依赖项?

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

How to add dependency to godep.json?

问题

我在将依赖项添加到Godeps.json文件时遇到了困难。我认为我搞乱了GOPATH。我尝试了各种警告上的建议,但都没有起作用。

我的GOPATH/Users/sarath/project

which go的输出是/usr/local/bin/go。如果我尝试运行godep save ./...,它会给我以下警告:

godep: [WARNING]: godep should only be used inside a valid go package directory and
godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH.
godep: [WARNING]:	Current Directory: /Users/sarath/project
godep: [WARNING]:	$GOPATH: /Users/sarath/project
godep: Unable to find SrcRoot for package .

我的pkg文件夹位于/Users/sarath/project下。

英文:

I'm having hard time to add a dependency to the Godeps.json file. I think I've messed up the GOPATH. I tried various suggestions on the warnings but none of them worked for me.
My GOPATH is /Users/sarath/project.
which go is /usr/local/bin/go. If I try to do godep save ./..., it is giving me the following warning:

godep: [WARNING]: godep should only be used inside a valid go package directory and
godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH.
godep: [WARNING]:	Current Directory: /Users/sarath/project
godep: [WARNING]:	$GOPATH: /Users/sarath/project
godep: Unable to find SrcRoot for package .

I have my pkg inside the /Users/sarath/project.

答案1

得分: 6

那绝对行不通。GOPATH不仅仅是某个项目的路径;它是一个包含binpkgsrc目录的根目录;src目录包含了以包名命名的项目目录。所以你应该从你的项目目录中运行godep,根据你当前的GOPATH,这个目录应该是/Users/sarath/project/src/<repopath>,例如/Users/sarath/project/src/github.com/sarath/myproject

英文:

That definitely won't work. GOPATH isn't just the path of some project; it's the root of a directory, which contains bin, pkg, and src directories; the src directory contains package-named directories for projects. So you should be running godep from your project directory, which (given your current GOPATH) should be /Users/sarath/project/src/&lt;repopath&gt; - e.g. /Users/sarath/project/src/github.com/sarath/myproject.

huangapple
  • 本文由 发表于 2017年7月26日 01:35:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/45310156.html
匿名

发表评论

匿名网友

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

确定