douguanci9158 2016-02-01 16:10
浏览 38
已采纳

Golang-如何通过示例程序来安排我的工作区?

I'm still trying to get my head around the Go workspace layout. I have a package, todinfo and a sample program which uses it, untod.

I currently have this arrangement of directories:

$GOPATH
+- bin...
+- pkg ...
+- src
   +- github.com
      +- longborough
         +- (others)...
         +- todinfo
            +- todinfo.go
            +- untod.go

I originally developed these two programs in separate directories. However, since untod is really part of the todinfo package, it seems more sensible to package it up as a single project, in the same directory.

But when I try to install (I've wrapped the reply onto three lines for clarity):

D:\Development\Go\src\github.com\longborough\todinfo>go install
 can''t load package: package github.com/longborough/todinfo: 
 found packages todinfo (todinfo.go) and main (untod.go) 
 in D:\Development\Go\src\github.com\longborough\todinfo

I hope I'm mistaken, but this smells a bit like Java, at least to the uninitiated.

What am I doing wrong? What Go commands should I use to install the package and then install the sample? Or, what is the correct directory arrangement?

  • 写回答

1条回答 默认 最新

  • dongze8698 2016-02-01 23:22
    关注

    This got me too. Think of it this way: untod is not part of the todinfo package, it's a consumer of the todinfo package (library). In fact, main is not really a package at all, just a marker to say that it's got an entrypoint and should be compiled into a binary.

    TLDR: you can put untod anywhere. In the root is probably sensible: it will then be named whatever the last dir component of your $GOPATH is. Alternatively, put it in cmd/untod/untod.go if you've got multiple binaries.

    After some more development, you might consider making a separate repo like github.com/longborough/todinfo-bins to keep them apart.

    Dave Cheney has some decent advice on the subject.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里