2016-07-31 00:12
浏览 72


I have a GitHub repo with some python code and some text files. However, I want to add some Golang code to my project.

So basically my issue is that I'm confused on where to set my GOPATH so I can work with Go source files in the same place that I work on python files. Do I set my GOPATH to my repo path, then setup the \src\\user\ directory and put my Go code there? Do I put Grandzam where user is, or leave it alone because someone else is working with me on the repo? Test your installation is what I am confused about.

图片转代码服务由CSDN问答提供 功能建议

我有一个带有一些python代码和一些文本文件的GitHub存储库。 但是,我想向我的项目中添加一些Golang代码。

所以基本上,我的问题是我对在哪里设置GOPATH感到困惑,因此我可以在处理python文件的同一位置使用Go源文件。 我是否将GOPATH设置为我的回购路径,然后设置\ src \ \ user \目录并将Go代码放在此处? 我应该将Grandzam放在用户所在的位置,还是因为其他人在仓库上与我合作而将其保留? 测试您的安装是否使我感到困惑。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutao1939 2016-07-31 00:57

    I would recommend setting up an environment consistent with the recommendations in the "Organizing your code" section of the language documentation.

    First, choose a top level directory (I tend to use ~/devel), and set the value of your GOPATH environment var to that location, and add the GOPATH/bin dir to your path. Put it in your the appropriate session startup file (~/.bash_profile or similar). In my case, I would put these lines in that file:

    export GOPATH=$HOME/devel
    export PATH=$GOPATH/bin:$PATH

    Quoting from the documentation:

    To give you an idea of how a workspace looks in practice, here's an example:

        hello                          # command executable
        outyet                         # command executable
                stringutil.a           # package object
            .git/                      # Git repository metadata
            hello.go               # command source
            main.go                # command source
            main_test.go           # test source
            reverse.go             # package source
            reverse_test.go        # test source
            .git/                      # Git repository metadata
            reader.go              # package source
            writer.go              # package source
        ... (many more repositories and packages omitted) ...

    Next, clone your git repo into the appropriate path under the $GOPATH/src tree. In my case it would be $GOPATH/src/

    Now you should be all set to work on both go and python code without much trouble.

    解决 无用
    打赏 举报

相关推荐 更多相似问题