Home > Backend Development > Golang > How to Handle Go Remote Imports with Non-Default Ports?

How to Handle Go Remote Imports with Non-Default Ports?

Mary-Kate Olsen
Release: 2024-12-06 14:46:14
Original
227 people have browsed it

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
Copy after login

To import this package, a typical approach would be:

import (
    "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
)
Copy after login

However, this often results in the error:

invalid import path: "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template