"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does \"go get\" Fail on My Personal Git Repository and How Can I Fix It?

Why Does \"go get\" Fail on My Personal Git Repository and How Can I Fix It?

Published on 2024-11-20
Browse:361

Why Does \

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$1 git git ssh://[email protected]$1"/></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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3