Skip to main content

Posts

Showing posts from 2019

Golang modules - everything, even your application, is a module

I’m new to golang modules . Here are some of the things that I wish I had known when I started using them. There is no reason to set GOPATH One of the things I struggled with was how to reconcile modules with the single workspace directory recommended in the golang docs and what was previously where GOPATH would point. With go modules you wouldn’t normally set GOPATH. Everything is a module Everything is a module. Even your application. This is something not immediately obvious or mentioned anywhere. Every module has to have a name If you aren’t planning to import or share your application/package then you can use a non-repository name like myapp . When you initialize go modules you can do: go mod init myapp If you’d like to share this as a module you’ll want to use its web location instead like: go mod init github.com/user/repo Packages need to be fully qualified If you had a subdirectory of your application called mypackage then you’ll have to adjust your impo