title: How to generate path relative to module path
body: <p>Say my module path in go.mod is: <code>module github.com/User/Project</code>, and I have a file structure like so:</p>
  <pre><code>.
  ├── go.mod
  └── pkg
      └── folder
          └── ...
  </code></pre>
  <p>Is there a way to run a Go program that will print, depending on the folder you are in, the path relative to the module path?</p>
  <p>Example:</p>
  <pre><code>$ (~) ./executable
  $ (~) github.com/User/Project
  </code></pre>
  <pre><code>$ (~/pkg/) ./executable
  $ (~/pkg/) github.com/User/Project/pkg
  </code></pre>
  <pre><code>$ (~/pkg/folder) ./executable
  $ (~/pkg/folder) github.com/User/Project/pkg/folder
  </code></pre>
  <p>My thought process so far is to use os.Getwd() and exec.cmd(&quot;go&quot;, &quot;env&quot;, &quot;GOMOD&quot;).Run() and then parse the go.mod file to find the module path etc..</p>