为什么我找不到遵循标准 src/pkg/bin 结构的任何 Go 包?

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

Why can't I find any go package which follows the standard src/pkg/bin structure?

问题

我是一个golang的初学者,我正在阅读go官网上的文章如何编写Go代码。文章解释了典型的Go项目结构在项目的根目录下包含三个文件夹:

bin/
    包含编译后的代码
pkg/
    包含包对象
src/
    包含Go源代码文件

所以为了从其他项目中学习,我查看了一些在GitHub上受欢迎的Go项目,但令我惊讶的是,这些项目中没有看到src/pkg/bin这样的结构。

我在这里错过了什么?有人知道一个(最好是简单的)遵循这种结构的Go项目吗?我认为通过阅读其他人的代码我可以学到很多。

英文:

I'm a beginner in golang, and I was reading the article How to write Go code on the go website. It explains how the typical Go structure contains three folders in the root of the project:

bin/
    contains compiled code
pkg/
    contains package objects
src/
    contains the Go source files

So to learn from other projects I checked out some popular go projects in github, but to my surprise I don't see this src/pkg/bin structure in any of those projects.

What am I missing here? Does anybody know a (preferably simple) project in golang which follows this structure? I think I could learn a lot from reading other people's code.

答案1

得分: 1

你在问题中提到的结构并不是项目的结构,而是本地工作空间的配置方式。

通常情况下,你会在本地机器上设置一个工作空间,例如将工作空间的根目录设置为:

$HOME/go

然后,你将GOPATH环境变量指向$HOME/go,以告诉Go这是你的工作空间位置。

在工作空间中,你可以创建srcbinpkg文件夹,正如文档中所描述的那样。

src文件夹中,你可以检出(或创建自己的)项目文件夹。

英文:

The structure you reference in your question is not how projects are structured but rather how the local workspace is configured.

https://golang.org/doc/code.html#Workspaces

Typically, you'll set up one workspace in your local machine, for example you would set up your workspace root to be:

$HOME/go

You then point your GOPATH environment variable to $HOME/go to let Go know that's your workspace location.

Inside your workspace you then create the src, bin and pkg folders that the documentation describes.

Inside src is where you checkout (or create your own) project folders.

huangapple
  • 本文由 发表于 2017年9月16日 21:27:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/46254423.html
匿名

发表评论

匿名网友

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

确定