1

Getting started with Go and going through the docs here: https://golang.org/doc/code.html

The part entitled Package paths recommends using my Github account as a base path. However, with the forward slashes in the GH url, when I run mkdir -p $GOPATH/src/github.com/user it creates a sub-folder. So the example of github.com/user creates:

src/
    github.com/
        user/

but I don't think this is what's intended.

What can I do here?

2 Answers 2

6

The behavior is correct. The packages names in Go provide unique global name space.

github.com/user/repo therefore identifies a package, which is easily go get -able (download and install the package) and also provides much needed separation. You can also create packages without a hostname (in this case github.com) but effectively preventing users from using go get and resorting to manual management.

Having a username in GitHub case allows you to use forks of other libraries and maintain the separation. The full package name is then used for importing

import "github.com/user/repo"
Sign up to request clarification or add additional context in comments.

Comments

4

This is actually the intended behavior,

You can even call go get on a github repo and it will create this same directory structure

1 Comment

Oh right - I don't think the example directory structure makes this clear but thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.