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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?