Home > Article > Backend Development > How to Make a Package Available for \'go get\' on a Personal Git Repository?
Using "go get" on a Personal Git Repository: A Comprehensive Guide
The Challenge
Attempting to make a package available for "go get" on a personal Git repository often results in the error message "unrecognized import path." This article provides a comprehensive solution to this issue.
Understanding the META Tag
Go requires a META tag in the root HTML page of the Git repository that specifies the package's import path and repository URL. The syntax is as follows:
<meta name="go-import" content="import_path git repo_url">
Setting Up the Server
For the "go get" feature to work, the server hosting the Git repository must be configured to return the META tag when a request is made with the "?go-get=1" parameter.
Recommended nginx Configuration
The following nginx rewrite rule can be used to achieve this:
location ~ "(/[^/]+/[^/]+)(/.*)?" { if ($arg_go-get = "1") { echo '<html><head><meta name="go-import" content="my.domain.com git git+ssh://[email protected]"/></head></html>'; } try_files $uri $uri/index.html $uri.html @gitlab; }
This rule assumes SSH access to the Git repository. If HTTPS is used, modify the URL accordingly.
Example META Tag
Requesting "http://mygit.server/group/project?go-get=1" should return the following META tag:
<meta content='mygit.server/group/project git git+ssh://[email protected]/group/project.git' name='go-import'>
Testing the Package
After configuring the server, you can verify if the package is available for "go get" by running:
<code class="Bash">go get example.com/user/package</code>
This command should successfully download and install the package.
The above is the detailed content of How to Make a Package Available for \'go get\' on a Personal Git Repository?. For more information, please follow other related articles on the PHP Chinese website!