doucan957495 2015-11-12 20:47
浏览 45
已采纳

不为我自己的软件包使用回购路径的含义

Suppose I decide to keep all personally developed packages organized as follows:

$GOPATH/
    bin/
    pkg/
    src/
        somepkg1
        somepkg2
        ...
        somepkgN

Further, suppose there is a great deal of code reuse among them, so I decide to keep the whole $GOPATH workspace under the same Git repository (each package could be a submodule), as opposed to more traditional scenario where subpackages are less coherent (co-existing solely because of using go get from the same workspace):

$GOPATH/
    bin/
    pkg/
    src/github.com/<me>/
        somepkg1
        somepkg2
        ...
        somepkgN

I can see that with the former approach (not using github.com/<me>/ in the package paths), go get would not be able to fetch packages as they are not "declaring" themselves to be available online. However, one can easily work around that by using git submodules, so all packages would be fetched in the first place (note it's a tightly controlled ecosystem so there will be no name clashes).

Is there any other limitation (besides go get) of not using full paths for packages?

(I am mostly concerned about limitations arising from certain code refactoring/analysis tools that exploit the repository path as base path convention that allows go get to look for the package online.)

  • 写回答

1条回答 默认 最新

  • douran7929 2015-11-12 21:13
    关注

    For the Go compiler and all elements of the go tool except go get the package import path is an almost opaque string containing the import path. You can lay out your code like you want (the compiler itself happy compiles files from different folders into one package). If you don't need or want your code to be go getable there is no need to use a repo path. The analysis and refactoring tools in golang.org/x/tools work on the opaque import paths (as far as I know) and do not access the network.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!