Golang, importing packages from Github, asks me to remember the Github URL?

I am very new to the Golang. I see that in Golang you can import packages directly from Github, for example:

import "github.com/MakeNowJust/heredoc" 

Does this mean that I have to remember this URL in order to use this package? IMHO this is not cool. What if a package author later deleted or changed a URL? Any ideas?

+16
github go package
source share
3 answers

I would recommend you read the documentation How to write a Directions Code and this blog.

The path you see in the import line is not the URL, but only the path where the package is located (usually relative to $GOROOT/src/pkg or $GOPATH/src ). Therefore, your heredoc package is most likely located in the $GOPATH/src/github.com/MakeNowJust/heredoc .

The recommended way to use external packages is to download and install them through go get . You might want to check the documentation at get go get --help .

+36
source share

Do not worry, man! you can use glide package management tool

+1
source share

The path referenced by the import statement is simply added to $GOPATH/src . So this import statement basically says: "import the package located at $GOPATH/src/github.com/MakeNowJust/heredoc "

What if the package author later deleted it or changed the URL?

If you already have the source files for this package in the expected location, it should be included, even if the repository has been moved.

0
source share

All Articles