dongliqin6939 2019-04-25 22:48
浏览 12
已采纳

无法将本地包调用为主

I feel like this is probably an over-asked question on SO yet here it is again. I'm finding this simple task incredibly tedious in Go. Note that I have GO11MODULES set to ON, I'm not sure if this effects the whole package system (it shouldn't is what I'm assuming).

I have a package called "users" which contains a compiled Protocol Buffer (from a .proto file). I want to store it alongside a number of other definitions in a folder called protos. So that my structure looks like so:

- main.go
- protos
   - users.go
   - users.proto
   - analytics.go
   - analytics.proto

Pretty simple structure. Within the users.go file I'm defining package protos. Within main.go I'd like to import users "protos/users". When I do so I get this: build command-line-arguments: cannot load protos/users: cannot find module providing package protos/users.

I've followed (I think) other sample code that has done the same thing. Note that the folder structure is within $GOPATH/src/myapi.

Why is this more complicated than its proving to be?

  • 写回答

2条回答 默认 最新

  • dqk94069 2019-04-26 13:41
    关注

    If you are using package protos, then the package is protos. protos/users does not exist. Packages and package imports are directory-level, not file-level. The full import statement depends on the module declaration in your go.mod file, which defines the root of imports. E.g., if your go.mod begins with

    module github.com/me/myapp
    

    Then your import would be

    import "github.com/me/myapp/protos"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度