Is there a best practice on workspace/package management?

Hi all!

I’m new to Go and recently accepted a job offer where it’ll be my primary working language. I’ve been reading / watching videos / playing with code for the last few days to be better prepared on my first day.

One thing that I’m having trouble wrapping my head around is how to manage workspaces and packages?

  • Is there an industry best practice on creating separate workspaces per project vs having one huge workspace with all projects?
  • Should “global” packages be managed outside of the workspace? For reference – VS Code wants me to install a bunch of extensions that get added as various users under directory “go/src/github.com/”; is it Go convention to house all of these alongside my project directories?

Some light Googling suggested that this is still in debate and that there’s not (yet?) an authoritative styling opinion here. Would love to hear the community’s thoughts!

Resolved VS Code issue by learning how to use setting go.toolsGopath. Definitely still interested to hear about how others are organizing projects.

Quoting Code Organization:

  • 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.

1 Like

Hi Farkhad, thanks for quoting that info from the docs! I’d seen a post on stack overflow where there were good points made both for following this convention and for going with something else (https://stackoverflow.com/questions/20722502/whats-a-good-best-practice-with-go-workspaces).

Being new here, I’m definitely interested in hearing about what other professionals are doing. Is this how you set up your workspace? What do you like and not like about it? TIA!

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