douzhuozhu9544 2015-09-03 14:40
浏览 161
已采纳

让golang语句传到github还是有相对路径更好,为什么?

In golang import statements, is it better to have something like:

import(
    'project/package'
)

or

import(
    'github.com/owner/project/package'
)

for files local to your project?

For either option, why would you want to do one over the other?

I ask this because while it's easy and more intuitive to do the first one, I've also seen a lot of big projects like Kubernetes and Etcd do it the second way.

  • 写回答

1条回答 默认 最新

  • douhuantui6259 2015-09-03 14:50
    关注

    These are exactly the same as far as the go build tools are concerned. The fact that package is in the directory

    $GOPATH/src/github.com/owner/project/package
    

    or in the directory

    $GOPATH/src/project/package
    

    makes no difference.

    The only difference is that with the former you can use go get to fetch the source automatically, and the latter you have to clone the code yourself.

    What you don't want to use are paths relative to the project itself, like

    import "./project/package"
    

    That is not compatible with all the go tools, and is highly discouraged.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化