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 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序