Home >Backend Development >Golang >How Can I Import a Go Library from a Private Git Repository on a Non-Default Port?
You have a private Git repository hosted on a non-default HTTP port (e.g., 6655) and need to import a library from that repository into your Go project. Attempting to do so directly using the syntax:
import "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
results in an error indicating an invalid import path.
Go modules support the use of a proxy to retrieve packages from private or non-publicly accessible repositories. To use this approach, follow these steps:
export GOPROXY=http://myproxy.example.com:8080
import "internal-git.corporate-domain.com/myuser/golang-lib"
Another option is to modify your .gitconfig file to handle non-default ports:
[url "git://[email protected]:6655"] insteadOf = git://internal-git.corporate-domain.com
This associates the non-default port with the internal Git repository URL.
import "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
The above is the detailed content of How Can I Import a Go Library from a Private Git Repository on a Non-Default Port?. For more information, please follow other related articles on the PHP Chinese website!