doufei5315 2019-06-10 08:40
浏览 134
已采纳

如何在golang中包含我的log包而不是内置的log包?

I have an log package in my project src folder. But when I include the log package from an another package as following, the go seams find the log in the system folder instead of my package.

import ("log")

And seams I cannot using relative path to import log package, because go install give following error:

local import "./log" in non-local package

So how can I let the go using my log package?

  • 写回答

1条回答 默认 最新

  • dtgvl48608 2019-06-10 11:58
    关注

    You need to add your package inside $GOPATH

    So if your package is in

    $GOPATH/src/github.com/ZijingWu/awesomeapp/src/
    

    your log package would be in

    $GOPATH/src/github.com/ZijingWu/awesomeapp/src/log
    

    then it would be possible to use

    import("github.com/ZijingWu/awesomeapp/src/log")
    

    The paths seams a bit strange tho, and maybe you should consider adding the log package as a completely separate repository on github, so it would look something like.

    import("github.com/ZijingWu/log")
    

    Just using github as an example here, could of course be placed wherever, also just guessing at your username there. Doesnt need to be in github either you can just place it localy on your computer in the $GOPATH, but then noone else would be able to build your package.

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

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题