Confused about project/workspaces

I am reading https://golang.org/doc/code.html#Overview which basically states:

  • Go programmers typically keep all their Go code in a single workspace .
  • A workspace contains many version control repositories (managed by Git, for example).
  • Each repository contains one or more packages .
  • Each package consists of one or more Go source files in a single directory.
  • The path to a package’s directory determines its import path .

Note that this differs from other programming environments in which every project has a separate workspace and workspaces are closely tied to version control repositories.

Sorry I am confused by the above description. Does this mean all my projects have to be under GOPATH/src? What is the logic behind this. What if I want to separate my projects and I want import to search multiple paths for user packages. How does one do this?

Thanks

1 Like

Either by not using go at all, or by using go modules. Can’t say much about the latter, as I’ve not done any go since they are a thing.

1 Like

Hi @wyattbiker we can use go modules if you want to keep a particular project in a different directory. But if you do that you loose the chance to import that project as a lib for other projects as go can not search for dependencies from root you can though use go get so that the source is available in the set workspace and use it. If you want to keep different projects separate you can change GOPATH for that workspace. Mostly workspace can be looked as a python env where you have your installed dependencies of a specific version. and place your source in the source dir. Workspace in go also help to keep code organized and not mix with binaries and packages.

1 Like

Is there a suggested virtualenv type environment to do that? Thanks!

1 Like

Golang team is continuously working on Dep tool. You can try this for now.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.