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条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格