Go工作区问题:如何区分本地包和远程包?

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

Go workspace issue: how to differ local packages from remote packages?

问题

我的gopath指向$HOME/go目录。我有一些个人包,我不想在GitHub或其他地方分享(至少现在不想)。然而,当我尝试使用go get -u all更新远程包时,我遇到了以下问题:

# cd /home/go/src/marcio/somePackage; git pull --ff-only
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
package code.google.com/p/go.tools/astutil
        ...
        一长串的依赖项
        ...
        imports marcio/somePackage: exit status 1

这非常令人困惑。我如何告诉go get区分我维护的包和用作依赖项的包?为什么go工具认为所有东西都必须从远程源获取?


更新:

看起来Go工作空间要求将依赖项与用户维护的代码混合在一起。这看起来很不稳定。有时候人们想要清除未使用的垃圾包,并冒着清除错误文件夹或未提交的内容等风险,还有许多其他问题...有没有办法将用户维护的包与远程获取的依赖项分开?

英文:

My gopath points to $HOME/go directory. And I have some personal packages that I don't want to share on github or anywhere else (yet). However when I try to update the remote packages with go get -u all I get:

# cd /home/go/src/marcio/somePackage; git pull --ff-only
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
package code.google.com/p/go.tools/astutil
        ...
        long list of dependencies
        ...
        imports marcio/somePackage: exit status 1

This is very confusing. How do I tell go get to differ the packages I maintain from the packages used as dependencies? Why the go tool thinks everything has to be fetched from a remote source?


UPDATE:

It looks like Go work spaces impose you to mix dependencies with user maintained code. This looks precarious. Sometimes ones want to wipe unused trash packages and live with the risk of wiping the wrong folder or uncommitted stuff, and many other problems... is there any way to keep user maintained packages separated from remote fetched dependencies?

答案1

得分: 4

go get -u 旨在通过版本控制系统获取更新。如果您想有选择地更新软件包,您将需要使用更具体的标识符。您仍然可以使用 ... 通配符。

例如,这将尝试更新来自 github.com 的所有软件包:

go get -u github.com/...

然而,总的来说,我建议避免盲目地更新所有内容,因为这会使跟踪依赖项是否破坏了某些内容变得更加困难,因为您当前未使用的不相关项目的依赖项也会被更新。

更新答案:

虽然您可以使用多个 GOPATH(它们与 PATH 一样用冒号分隔),但不要这样做;这会带来更多问题。使用单个 GOPATH,甚至更好的是每个项目使用单独的 GOPATH。这样,您可以更新依赖项而不会影响其他项目。有一些供应工具可以帮助您实现这一点(例如 godep)。

英文:

go get -u is designed to fetch updates via VCS. If you want to selectively update packages, you'll have to use a more specific identifier. You still have the ... wildcard to use too.

For example, this will try and update all packages from github.com:

go get -u github.com/...

In general though, I would avoid blindly updating everything, as it would make it harder to track when a dependency has broken something, since unrelated projects you're not currently working with will have their dependencies updated too.

Update answer:

While you can operate with multiple GOPATH's (they're colon separated just like PATH), don't do it; it will cause more problem than it helps with. Use a single GOPATH, and even better, use a single GOPATHper project. That way you can update dependencies without risk of affecting other projects. There's are some vendoring tools you can look into to help with this (godep for example)

huangapple
  • 本文由 发表于 2014年12月3日 21:59:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/27273588.html
匿名

发表评论

匿名网友

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

确定