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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号