title: Structuring Go subpackages for teams
body: <p>We are currently moving some of our codebase to Go and are struggling a bit with a flexible directory structure for multiple devs within a team. Apologies if this is a noob question but I've searched everywhere else and not come up with an answer.</p>
  
  <p>Say I have a package with the following structure:</p>
  
  <pre><code>package main
  
  import "username/myproject/subpackage"
  
  func main() {
  
  }
  </code></pre>
  
  <p>and a subpackage:</p>
  
  <pre><code>package subpackage
  
  func main() {
  
  }
  </code></pre>
  
  <p>This works fine and from reading other peoples code on Github, it seems like this is the accepted way to define subpackages.</p>
  
  <p>See the CoreOS source as an example: <a href="https://github.com/coreos/etcd/blob/master/main.go">https://github.com/coreos/etcd/blob/master/main.go</a></p>
  
  <p>My problem is that due to the directory structure of Go, these packages are stored within a specific git repo and if someone else in the team checks out this code to work on, their directory structure will be different due to forking. The username in the paths and the import statements will change. This isn't helped by the fact we pull and push a lot to each other rather than using a centralised repo.</p>
  
  <pre><code>package main
  
  import "otherusername/myproject/subpackage" (This line will have to be changed)
  
  func main() {
  
  }
  </code></pre>
  
  <p>Everything I have read about Go points to its usability in team environments so I'm wondering if I'm understanding the package system properly.</p>
  
  <p>Ideally we would like to be able to call subpackages with relative paths. We are used to working with namespaces and I know Go doesn't have them. ie:</p>
  
  <pre><code>package main
  
  import "myproject/subpackage"
  
  func main() {
  
  }
  </code></pre>
  
  <p>But Go can't find the file and I'm sure it's not the right way of doing it as no examples online use relative paths.</p>
  
  <p>So a couple of questions:</p>
  
  <p>1) Should packages have a defined owner and always keep that username as part of the import paths? </p>
  
  <p>2) Should this "owner" repo be a centalised repository (say a company or organisation) that all code is pushed to / pulled from?</p>
  
  <p>3) Should other team members working on a piece of code use it within the creators folder/namespace rather than their own?</p>
  
  <p>4) Is there a way to define relative paths in import statements, and if so, why does no-one do it? Is it considered bad practice?</p>
  
  <p>5) How is repo forking handled with Go subpackages?</p>
  
  <p>Thanks.</p>