doukan1258 2018-10-16 17:05
浏览 1870

go.mod文件的放置位置

I have a repository structure as follows :-

xyz/src
      1. abc
            - p
            - q
            - r
      2. def
            - t
            - u
            - v
      3. etc
            - o
            - m
            - n

I have created a .mod file in src and run go build ./... Except for local packages everything is fine. So if abc/p is being used in def then it throws the following exception :- cannot find module providing package abc/p. The idea behind keeping the .mod file in src package was to make sure the path is being found from where the mod file is located. Can anyone suggest where should the mod file ideally should be? also i tried placing it one directory above in xyz but still same issue as well as i created one for each sub directory. I am bit confused on this. Will I have to create separate repository for abc and etc. But considering gopath which earlier used to work for the same I think module should also be able to do the same. Any suggestions?

  • 写回答

2条回答 默认 最新

  • dongtan4046 2018-10-17 13:49
    关注

    I have a single go.mod in the root of my go application. I am using the following structure inspired by Kat Zien - How Do You Structure Your Go Apps

    At the minute one of my applications looks like this

    .
    ├── bin
    ├── cmd
    │   ├── cli
    │   └── server
    │       └── main.go
    ├── pkg
    │   ├── http
    │   │   └── rest
    |   │ # app-specific directories excluded
    │   └── storage
    │       └── sqlite
    

    All packages are imported via their full path, i.e. import "github.com/myusername/myapp/pkg/http/rest" otherwise it causes problems all over the place and this was the one change I had to make going from $GOPATH to go mod.

    go mod then handles all the dependencies it discovers properly as far as I've discovered so far.

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多