golang意外的目录布局

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

golang unexpected directory layout

问题

所以我从github.com/minio/minio下载了minio。

我想从源代码运行它,

我创建了我的目录,如下所示:

~/Downloads/minio-RELEASE.2017-06-13T19-01-01Z
|
 src
   |
    所有minio目录,包括vendor,如下图所示

golang意外的目录布局

我还使用godep解决了GOPATH下的其他依赖项。

现在我从Gogland(go IDE)运行它

它显示:

GOROOT=/usr/local/Cellar/go/1.8.3/libexec
GOPATH=/Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z:/Users/xl/go
/usr/local/Cellar/go/1.8.3/libexec/bin/go build -i -o /private/var/folders/8v/6dg7d6mx2850sv1gp8ts9thm0000gn/T/go_run_main_gogo /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/main.go
unexpected directory layout:
	import path: github.com/Azure/azure-sdk-for-go/storage
	root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
	dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
	expand root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
	expand dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
	separator: /

现在我很困惑,问题出在哪里?文件都在那里,目录结构也和打印的一样。我该如何解决它?谢谢。

英文:

So I downloaded minio from github.com/minio/minio

I want to run it from the source,

I create my directory like:

~/Downloads/minio-RELEASE.2017-06-13T19-01-01Z
|
 src
   |
    all minio directories, including vendor, like the image below

golang意外的目录布局

I also use godep resolve other dependencies under GOPATH.

Now I run it from Gogland(go IDE)

It shows:

GOROOT=/usr/local/Cellar/go/1.8.3/libexec
GOPATH=/Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z:/Users/xl/go
/usr/local/Cellar/go/1.8.3/libexec/bin/go build -i -o /private/var/folders/8v/6dg7d6mx2850sv1gp8ts9thm0000gn/T/go_run_main_gogo /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/main.go
unexpected directory layout:
	import path: github.com/Azure/azure-sdk-for-go/storage
	root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
	dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
	expand root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
	expand dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
	separator: /

Now I am confused that, what's the problem? The files are all there and the directories are just like what's it's printing. How do I fix it? Thanks.

答案1

得分: 26

在升级到Golang 1.13后,我所有的代码都突然出现了问题。似乎Golang 1.13不再支持类似"./something"这样的导入方式。我不得不将所有的导入改为"myapp/something"这样的形式。

英文:

On Golang 1.13 it suddenly happened to me on all my code after upgrading from 1.11 to 1.13.

It seems golang 1.13 does not like anymore imports like "./something".

I had to develop any import like "myapp/something"

答案2

得分: 8

请参考GitHub代码布局

> $GOPATH是项目的根目录 - 每个Github仓库都会被检出到$GOPATH下的几个文件夹中。
你的$GOPATH变量将指向你的Go工作区的根目录,具体请参考如何编写Go代码

在你的情况下,你的GOPATH文件夹下应该有

src/github.com/minio/minio

然后才是"所有minio目录,包括vendor"

英文:

See GitHub code layout

> $GOPATH is the root of the project - each of your Github repos will be checked out several folders below $GOPATH.
Your $GOPATH variable will point to the root of your Go workspace, as described in How to Write Go Code.

In your case, below your GOPATH folder, you should have

src/github.com/minio/minio

Anf only then "all minio directories, including vendor"

答案3

得分: 6

这可能是因为你在 goroot 和 gopath 下有重复的存储库。请删除 goroot 下的那个。

英文:

This can happen if you have duplicate repos under goroot AND gopath. Delete the goroot one.

答案4

得分: 3

此外,使用go1.13(使用go mod进行移动)时,我发现如果将我的项目移出$GOPATH,我可以使用**import "./mypackage"**语句。在$GOPATH下的同一项目将无法构建,会出现上述错误。我还不准备放弃我的$GOPATH环境变量,但我确实希望在可能的情况下将小包保持在项目本地,而不需要提交go.mod文件。

英文:

Also with go1.13 (with the move to go mod), I found if I moved my project out from under my $GOPATH, I could use the import "./mypackage" statement. The same project under $GOPATH wouldn't build with the errors given by the OP above. I'm not ready to give up my $GOPATH environment variable just yet but I do like to keep small packages local to their project when possible, without committing to a go.mod file when it's not necessary.

答案5

得分: 1

如果你的项目文件夹在$GOPATH目录下,那么你应该在导入包时不使用"./package"。

只有当你的项目文件在$GOPATH之外时,才可以使用"./package"来导入包。

英文:

If your project folders are under $GOPATH directory, Then you should import your packages without using "./package".

You can import packages with "./package" name only if your project files are outside the $GOPATH

答案6

得分: 0

我在意识到由于项目位置的原因,我无法正确导入本地包后遇到了这个问题。我的项目不在GOPATH位置,所以我将项目移动到了那里。在移动之前,我通过./包名导入包,移动项目到GOPATH后,我通过项目名/包名正确导入包。

所以我所做的就是以正确的方式导入包"项目名/包名",所以我将我的导入"./包名"更正为"项目名/包名"。希望这不会太令人困惑。看起来这个错误可能出现在不同的情况下。

英文:

I had this issue after I realised that I can't import correctly local packages, due to my project location.
My project was not in the GOPATH location, so I moved my project there. Before moving

I imported packages via ./package name and after I moved my project in the GOPATH, I imported packages correctly via projectname/packagename.

So what I've done was to import packages the correct way "projectname/packagename", so I corrected my import "./packagename" to ""projectname/packagename.
Hopefully it's not too confusing. It seems that this error can appear from different situations.

huangapple
  • 本文由 发表于 2017年8月1日 11:59:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/45428744.html
匿名

发表评论

匿名网友

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

确定