douxi3404
douxi3404
2019-08-06 16:55

如何使用Go模块在特定分支上导入软件包

  • IT行业问题
  • 计算机技术
  • it技术
  • 编程语言问答
  • 互联网问答
已采纳

I'm reorganizing a repo from the following structure:

repo_root/
   |- foo/
       |- foo.go
   |- bar/
       |- bar.go
   |- go.mod

into the following:

repo_root/
   |- gosrc/
        |- foo/
             |- foo.go
        |- bar/
             |- bar.go
        |- go.mod

Now, inside foo.go of the original repo structure, I do something like below to import the package bar:

import "github.com/arb_name/repo_root/bar"

Now, with the new repo, I changed it to:

import "github.com/arb_name/repo_root/gosrc/bar"

Now, I run into the problem that go build of foo.go failed because

cannot find module providing package github.com/arb_name/repo_root/gosrc/bar

I certainly do not want to change the master branch of repo without first making sure that the restructure of repo works. I'm wondering if there is a way to solve my situation? I can work on my fork but ideally not directly making change to my fork's master.

Thanks!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • drvvvuyia15070493 drvvvuyia15070493 2年前

    Make sure that you updated your go.mod file to

    module github.com/arb_name/repo_root/gosrc

    点赞 评论 复制链接分享

为你推荐