title: Migrate to Go modules while keep on using distribution packages
body: <p>I have a GOPATH based project that I currently build like this on Fedora:</p>
  <pre><code>sudo dnf install golang-etcd-bbolt-devel golang-x-sys-devel golang-x-text-devel
  GOPATH=$HOME/go:/usr/share/gocode go build
  </code></pre>
  <p>My project (<a href="https://github.com/gsauthof/gonzofilter" rel="nofollow noreferrer">gonzofilter</a>) implements a command line utility and thus source files are located in the main package (i.e. they have  a <code>package main</code> declaration).</p>
  <p>With Fedora 34 and beyond it seems that Go removed support for building GOPATH style projects and one really has to use Go modules:</p>
  <pre><code>go build
  go: cannot find main module; see 'go help modules'
  </code></pre>
  <p>That <a href="https://blog.golang.org/migrating-to-go-modules#TOC_4." rel="nofollow noreferrer">Go blog post</a> kind of covers my case (-&gt; 'Without a dependency manager'), but it doesn't explicitly mention how to deal with main package projects or with distribution provided dependencies.</p>
  <p>So, how do I migrate such a project?</p>
  <p>How do I have to tell Go/<code>go mod tidy</code> to look for my dependencies under <code>/usr/share/gocode</code>?</p>
  <hr />
  <p><strong>Edit:</strong> To be precise: Fedora 34 comes with Go 1.16 which 'just' changed the <code>GO111MODULE</code> default from <code>auto</code> to <code>on</code>. Thus, one still can restore the old behavior by setting <code>GO111MODULE=auto</code>.</p>
  <p>However, Golang developers already <a href="https://blog.golang.org/go116-module-changes" rel="nofollow noreferrer">announced</a> that they want to drop support for GOPATH style projects in Go 1.17:</p>
  <blockquote>
  <p>We plan to drop support for GOPATH mode in Go 1.17. In other words, Go 1.17 will ignore GO111MODULE. If you have projects that do not build in module-aware mode, now is the time to migrate.</p>
  </blockquote>