在 Golang 中不推送代码的情况下导入包的本地更改

Imr*_*tif 6 import package go vendor

我现在正在学习 Golang,而且是个新手。我有一个关于包裹的问题。

考虑以下场景:

想象一下,我有一个github.com/ilatif/A正在导入另一个包的包github.com/ilatif/B,例如:

import "github.com/ilatif/B"

现在,既然github.com/ilatif/Agithub.com/ilatif/B都是我的包并且我正在本地处理它们,有没有办法从github.com/ilatif/B包中提取更改而不将代码推送到 GitHub?根据 Golang 的文档,我需要将代码推送到其相关的存储库,但我想知道是否有这样一种方法可以在不将其推送到上游的情况下提取我自己的包的本地更改。

谢谢

Mar*_*les 11

Go 模块解决方案

通过在文件中使用替换,我可以成功地将 Golang 与模块一起使用go.mod

https://thewebivore.com/using-replace-in-go-mod-to-point-to-your-local-module/

  • 只要你go.modreplace语句保存文件,Goland 就会识别更新的模块。

例子

  • 使用 replace MODULE_URL => /PATH/TO/MODULE/DIR
    • 无需指定版本
module github.x.com/services-x/x

go 1.13

require (
    github.com/briandowns/spinner v1.8.0
    github.com/golang/protobuf v1.3.1
    github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
    github.com/marcellodesales/cloner v0.0.0-20191126082454-c952bef1e067
    github.com/mitchellh/go-homedir v1.1.0
    github.com/mitchellh/mapstructure v1.1.2
    github.com/sirupsen/logrus v1.2.0
    github.com/spf13/cobra v0.0.5
    github.com/spf13/viper v1.4.0
    github.com/thoas/go-funk v0.4.0
    gopkg.in/src-d/go-git.v4 v4.13.1
    gopkg.in/yaml.v2 v2.2.2
)

replace github.com/marcellodesales/cloner => /Users/mdesales/dev/github.com/marcellodesales/cloner
Run Code Online (Sandbox Code Playgroud)