patterngoCritical
Using forked package import in Go
Viewed 0 times
importpackageforkedusing
Problem
Suppose you have a repository at
Now all the import paths in this repo will be "broken", meaning, if there are multiple packages in the repository that reference each other via absolute URLs, they will reference the source, not the fork.
Is there a better way as cloning it manually into the right path?
github.com/someone/repo and you fork it to github.com/you/repo. You want to use your fork instead of the main repo, so you do ago get github.com/you/repoNow all the import paths in this repo will be "broken", meaning, if there are multiple packages in the repository that reference each other via absolute URLs, they will reference the source, not the fork.
Is there a better way as cloning it manually into the right path?
git clone git@github.com:you/repo.git $GOPATH/src/github.com/someone/repoSolution
If you are using go modules. You could use
The
be another module located in VCS (GitHub or elsewhere), or on your
local filesystem with a relative or absolute file path. The new import
path from the
import paths in the actual source code.
So you could do below in your go.mod file
where
replace directiveThe
replace directive allows you to supply another import path that mightbe another module located in VCS (GitHub or elsewhere), or on your
local filesystem with a relative or absolute file path. The new import
path from the
replace directive is used without needing to update theimport paths in the actual source code.
So you could do below in your go.mod file
module some-project
go 1.12
require (
github.com/someone/repo v1.20.0
)
replace github.com/someone/repo => github.com/you/repo v3.2.1where
v3.2.1 is tag on your repo. Also can be done through CLIgo mod edit -replace="github.com/someone/repo@v0.0.0=github.com/you/repo@v1.1.1"Code Snippets
module some-project
go 1.12
require (
github.com/someone/repo v1.20.0
)
replace github.com/someone/repo => github.com/you/repo v3.2.1go mod edit -replace="github.com/someone/repo@v0.0.0=github.com/you/repo@v1.1.1"Context
Stack Overflow Q#14323872, score: 192
Revisions (0)
No revisions yet.