dongzi5673 2019-02-14 01:01
浏览 187


This sounds stupid, but I am trying for build my new golang project for a while now and I am stuck with following error

can't load package: package found packages main (main.go) and yamqclient (yamq-client.go) in C:\projects\yamq\cmd\yamq-client

I know this should be straightforward to fix, but I come from .NET and I am still not experienced in Go projects and its dependency resolution model hence the struggle.

My project structure looks like so

        /yamq-client          // yamq client application binary
            main.go           // package main
            yamq-client.go    // package yamqclient
        /yamq-server          // yamq server application binary
            main.go           // package main
            yamq-server.go    // package yamqserver
    go.mod                // contains only "module" for now
    ... // some library files that will probably be moved to /shared folder

so far so good, when I do go build in outermost directory ( /yamq ) it is building successfully (or at least it is not showing any errors), but when I try to build either yamq-client or yamq-server binaries I get the aforementioned error and every time I try to google it or find something useful I got some old article or answer that dates back 2013-2016 that suggests something about $GOPATH and etc which shouldn't be the case here since I am trying to use go modules.

Help a fellow .NET developer join Go community by explaining him how exactly modules work cause I found this and this useless or at least I am missing the point, thanks in advance!

  • 写回答

2条回答 默认 最新

  • dongren1353 2019-02-14 19:56

    To follow up from my comment above:


    • Go programmers typically keep all their Go code in a single workspace.
    • A workspace contains many version control repositories (managed by Git, for example).
    • Each repository contains one or more packages.
    • Each package consists of one or more Go source files in a single directory.
    • The path to a package's directory determines its import path.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥20 判断两个表是否完全相同
  • ¥20 工控机出现散热器转一下停一下这种情况,是什么原因造成的
  • ¥15 双显卡,启动docker容器报错。
  • ¥15 想编写一个期货跨期套利的程序
  • ¥15 一个线程在sleep的时候set一个信号会起作用吗
  • ¥100 需求高精度PT100设计电路和算法
  • ¥15 单片机配网,继电器开关,广播
  • ¥60 Qcustomplot绘制实时动态曲线
  • ¥20 运用matlab画x-y图
  • ¥15 用idea运行项目,运行tomcat报错:断言失败