Go Modules In Real Life

Chip Keyes
Programming Is Hard
12 min readJul 16, 2019

--

UPDATE: I’ve written a follow up article with some improvements to my approach which you can read about here.

Ok, so Go modules are the new hot thing in Go ever since their beta release in version 1.11. If you’ve spent time working in Go you know that it’s a simple language that packs some powerful features. Also, if you’ve spent anytime working in Go before 1.11 you know about the infamous GOPATH. It was one of the most confusing things for me while learning and using Go. It only takes a simple google search for the term GOPATH to show how challenging it has been to the Go community. Suffice it to say, Go developers have been pretty ecstatic about modules since they address a lot of frustrations people had in previous versions.

But Go modules aren’t without their own complexities and challenges. Nor do they have the historical blogs and forum posts to help the new comer out. One area that I’ve struggled with in my team’s project is how to organize your code in a way that shares common packages to one or more main programs. It took me a while to find a solution that worked and didn’t seem like an anti-pattern but it has made this much simpler in our project. So my hope is that in sharing what we came up with, it might save you some trouble.

Either that or you can point out how we’re doing it wrong so we can improve our code.

--

--