dtbiszu7724 2019-09-21 23:27
浏览 53

在“如何编写Go代码”示例中,我是否对Go工作区中的git存储库结构感到困惑?

I have 2 points of confusion about the How to Write Go Code article. They may be mistakes in the article, or I may just be missing the point. In describing the structure of the typical workspace, the article says

The src subdirectory typically contains multiple version control repositories (such as for Git or Mercurial) that track the development of one or more source packages.

The first example workspace in the article matches this description, with 2 folders representing repositories (github.com/golang/example/ and golang.org/x/image/), each of which has a .git directory immediately below it.

Later, the article says:

If you're using a source control system, now would be a good time to initialize a repository, add the files, and commit your first change. Again, this step is optional: you do not need to use source control to write Go code.

Then the article shows example code running git init in the src/github.com/user/hello/ directory. This is point of confusion #1. Since github.com/user is the repository and hello is the package, it seems like the git init should be done at the level of github.com/user.

Point of confusion #2 comes near the end of the article, when it says:

After issuing the above go get command, the workspace directory tree should now look like this:

It then shows another example repository, which has a .git directory under the github.com/golang/example/ directory, but none under the github.com/user/ directory, either right below it or in the hello package where it was initialized earlier.

My questions are:

  1. Should the repository have been initialized in the hello directory or one level up?
  2. Should the final repository show a .git directory?
  • 写回答

3条回答 默认 最新

  • doudouji2016 2019-09-21 23:35
    关注

    The documentation you linked to does not show directory trees accurately - they combine directory names together which means directories of the same depth don't necessarily appear to have the same depth.

    This is not the documentation being wrong - it's fairly common to flatten directory trees to avoid wasting screen-space (especially in Java projects where you'll have many directories all containing only a single subdirectory due to Java's file/package naming convention enforced by their compiler).

    The tree diagram after "After issuing the above go get command, the workspace directory tree should now look like this:" should really look like this:

    bin/
        hello                                   # command executable
    src/
        github.com/
            golang/
                example/
                    .git/                       # 
                    hello/
                        hello.go                # 
                    stringutil/                 #
                        reverse.go              # 
                        reverse_test.go         # 
            user/
                hello/                          # "github.com/user/hello" package repo root
                    hello.go                    # 
                stringutil/                     # "stringutil" package source root, but not a repo
                    reverse.go                  # 
                    reverse_test.go             # test source
    

    Note that github.com/user is described as a "base path" and not as a repository root or package path, but github.com/user/hello is described as a package root.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题