drip5880 2018-09-12 13:12
浏览 6107

golang模块和本地包

I'm trying to understand how to organize my golang project using go1.11 modules. I tried several options, but none of them worked.

I have a some code in the main package, ander application folder, and a local package that the main package uses.

$GOPATH
+ src
  + application/
    + main/
      + main.go
      + otherFileUnderMainPackage.go
    + aLocalPackage/
      + someCode.go
      + someCode_test.go
      + someMoreCode.go
      + someMoreCode_test.go

Files in the main package, imports ../aLocalPackage. When I compile by go build main/*.go it's working.

Then, I ran go mod init application:V.0.9.9 and got the go.mod file, but the build always fails. I always get error about not finding the local package: build application:V0.9.9/main: cannot find module for path _/.../src/application/aLocalPackage. I also tried to place the local package right under src/, place it under main/ etc. but none of these method worked for me.

What is the way to use modules and local packages?

Thanks.

  • 写回答

1条回答 默认 最新

  • dongwei9365 2019-07-30 19:31
    关注

    Relative import paths are not supported in module mode. You will need to update your import statements to use a full (absolute) import path.

    You should also choose a module name other than application. Your module path should generally begin with a URL prefix that you control — either your own domain name, or a unique path such as github.com/$USER/$REPO.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!