Home >Backend Development >Golang >How to Handle Go Remote Imports with Non-Default Ports?
Remote Import with Non-Default Ports in Go
Importing remote Go packages can occasionally require specifying non-default ports. When working with corporate or self-hosted git repositories, it's common to encounter this scenario.
Initial Attempt
Consider a private git repository listening on port 6655:
http://internal-git.corporate-domain.com:6655/~myuser/golang-lib.git
To import this package, a typical approach would be:
import ( "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git" )
However, this often results in the error:
invalid import path: "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
Modified Approach
One solution is to modify the .gitconfig file to work with non-default ports:
[url "[email protected]:6655"] insteadOf = git://internal-git.corporate-domain.com
This configures Git to use port 6655 when accessing the specified repository. By making this change, the import statement will now work as intended.
The above is the detailed content of How to Handle Go Remote Imports with Non-Default Ports?. For more information, please follow other related articles on the PHP Chinese website!