dongzi5673 2019-02-14 01:01
浏览 187
已采纳

如何解决Go项目中嵌套应用程序二进制文件中的依赖项?

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 github.com/kuskmen/yamq/cmd/yamq-client: 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
    /cmd
        /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 github.com/kuskmen/yamq" 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:

    From https://golang.org/doc/code.html:

    • 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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 (标签-python)
  • ¥15 第一个已完成,求第二个做法
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳