unrecognized import path (import path does not beg

2020-07-22 18:01发布

问题:

I've installed go as per the custom installation clause of the installation instructions, as I have installed to a user directory, in order to accommodate having multiple versions of go.

When I go get . from my go project's src directory, I get the error message type already mentioned above ―

unrecognized import path (import path does not begin with hostname)

Can you please explain, why does go look for a hostname and how that should possibly be avoided in a typical project?

As an aside, the problem was originally encountered by me in setting up the following specific project and hash, which the accepted answer still refers to.

回答1:

go get downloads dependencies and packages by assuming that the import path (in the import statements in source code) identifies a URL where the package can be downloaded, e.g. github.com/habeanf/yap. It works so long as developers use imports correctly; unfortunately, the developer of the yap project did not.

Where they import yap/app, they should be importing github.com/habeanf/yap/app, etc. The only fix would be to clone the GitHub repo into $GOPATH/src/yap manually and then try to build it. You might want to open a GitHub issue on that project and request that they fix the import paths so it can be built like a normal Go project.



标签: go