matanox
matanox

Reputation: 13686

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

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.

Upvotes: 9

Views: 26259

Answers (2)

White Zebra
White Zebra

Reputation: 339

I had the same problem with setting up the same project on windows (note: updated project documentation is here).

Turns out GOPATH was set up for my username by GO installation while I updated the system environment GOPATH according to this description from the docs:

Set $GOPATH environment variable to your workspace: export GOPATH=path/to/yapproj

Removing GOPATH for my username solved the problem and I managed to build the application.

I'm posting this to prevent others from spending too much time on this issue as I did.

Upvotes: 0

Adrian
Adrian

Reputation: 46413

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.

Upvotes: 7

Related Questions