我现在正在学习 Golang,而且还是个新手。我有一个关于包裹的问题。
考虑以下场景:
假设我有一个包裹github.com/ilatif/A
我正在其中导入另一个包github.com/ilatif/B
, like:
import "github.com/ilatif/B"
现在既然两者github.com/ilatif/A
and github.com/ilatif/B
是我的包,我正在本地处理它们,有没有办法从中提取更改github.com/ilatif/B
打包而不将代码推送到 GitHub?根据 Golang 的文档,我需要将代码推送到其相关的存储库,但我想知道是否有一种方法可以拉取我自己的包的本地更改,而无需先将其推送到上游。
Thanks
Go模块解决方案
我可以通过在文件中使用替换成功地将 Golang 与模块一起使用go.mod
.
https://thewebivore.com/using-replace-in-go-mod-to-point-to-your-local-module/ https://thewebivore.com/using-replace-in-go-mod-to-point-to-your-local-module/
- 一旦您保存
go.mod
文件与replace
声明中,Goland 认可了更新的模块。
Example
- Using
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)