title: Is there a way to run a Go module from another directory
body: <p>I have the following project structure, outside of <code>GOPATH</code>.</p>
  <pre><code>. // Project root
  ├── Dockerfile
  ├── .env
  ├── README.md
  └── src
      ├── main.go
      ├── go.mod
      ├── go.sum
      ├── internal
      │   ├── somepackage
      │   │   ├── main.go
      │   │   └── types.go
      │   ├── someother
      │   │   ├── main.go
      │   │   ├── oauth.go
      │   │   └── types.go
      │   └── models
      │       └── main.go
      └── pkg
          ├── somepackage
          │   └── main.go
          └── anotherpackage
              └── main.go
  </code></pre>
  <p>I want to run my Go module code located in the <code>src</code> directory.
  When I <code>cd</code> into the <code>src</code> directory and <code>go run .</code> or <code>go build .</code> my code, it works perfectly.</p>
  <p>When I stand at the root of my project, I am unable to run <code>go run ./src</code> or <code>go build ./src</code>. I get the following error.</p>
  <pre><code>src/service.go:8:2: cannot find package &quot;web-service/internal/auth&quot; in any of:
          /usr/lib/go/src/web-service/internal/auth (from $GOROOT)
          /home/miloertas/Packages/go/src/web-service/internal/auth (from $GOPATH)
  src/endpoints.go:3:8: cannot find package &quot;web-service/internal/handlers&quot; in any of:
          /usr/lib/go/src/web-service/internal/handlers (from $GOROOT)
          /home/miloertas/Packages/go/src/web-service/internal/handlers (from $GOPATH)
  </code></pre>
  <p>It's important that my source code remains in this <code>src</code> directory.
  It is equally important that I am able to <code>run</code> and <code>build</code> my code from the root of my project (For example the <code>.env</code> file is located at the root of the repository).</p>
  <p>I am therefore looking for a way to <code>run</code> or <code>build</code> my code in the <code>src</code> directory from the root of my project.</p>
  <p>I tried moving the <code>go.mod</code> at the root of the project and running and ran <code>go run ./src</code> but this causes issues of its own:</p>
  <ul>
  <li>The <code>go</code> command is now unable to locate all the sub-packages in <code>internal</code> and <code>pkg</code></li>
  <li>VSCode is now lost and executing tests is impossible for some reasons (Mainly because all sub-packages are not found).</li>
  </ul>