Using Go Get for Local Server Repositories
Getting packages from a local server using go get can be challenging due to its expectation of HTTP-based repositories.
To resolve this issue:
For Packages (GOPATH Convention)
- Add the following to .gitconfig: git config --global url."user@host:".insteadOf "https://github.com/"
- Create git repositories on your private git server and use SSH public key access.
- Use go get with the suffix .git to retrieve packages: go get user@host:gitrepo/package/
For Modules
- Follow the steps above for packages.
- Set GOPRIVATE to specify the private repositories: go env -w GOPRIVATE=user@host/gitrepo/*
- Use go get with the suffix .git to retrieve modules: go get user@host/gitrepo/module/
Differences from Public Repositories
- Modifying .gitconfig to use SSH for private repositories.
- Adding .git suffix in go get for non-public repositories.
- Ensuring the hostname has a dot (.) or using its IP address.
Notes
- Go gets modules from the $GOPATH/pkg/mod directory.
- Semantic versioning is done with tags, which are independent of branches.
- To get the latest commit on a branch, use @branchname in go get, e.g. go get user@host/gitrepo/module/branchname
The above is the detailed content of How Can I Use `go get` with Local Private Git Repositories?. For more information, please follow other related articles on the PHP Chinese website!