Using "go get" on a Personal Git Repository
When attempting to make one of your packages "go get"-able from your personal VPS, you may encounter the error: "package example.com/user/package: unrecognized import path". This issue arises even after seemingly correct configuration following the "go help importpath" documentation.
The resolution lies in configuring the server to return a specific meta tag in response to "go get" requests. For nginx servers specifically, the following rewrite rule can be used:
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; }
When "go get" requests are made to the specified URL with the "go-get=1" argument, the provided meta tag will be returned. This meta tag includes the import path, version control type (git), and the SSH URL for the repository.
Ensure that the SSH URL is correct, as this is what go will use to download and install the package. If you are using HTTPS instead of SSH, modify the meta tag accordingly.
The above is the detailed content of Why Does \'go get\' Fail on My Personal Git Repository and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!