title: How to get the environment variables in the hook script of the golang-buildpack in Heroku?
body: <p>I have met a very odd issue, when I was building the script of the automation for the DB migration. I followed the official document:</p>
  <blockquote>
  <p>Pre/Post Compile Hooks</p>
  <p>If the file bin/go-pre-compile or bin/go-post-compile exists and is executable then it will be executed either before compilation (go-pre-compile) of the repo, or after compilation (go-post-compile).</p>
  <p>Because the buildpack installs compiled executables to bin, the go-post-compile hook can be written in go if it's installed by the specified  (see above).</p>
  </blockquote>
  <p>Then I crafted the <code>go-post-compile</code> script below:</p>
  <pre><code>var (
      appURI := os.Getenv(&quot;APP_URI&quot;)
      databaseURL := os.Getenv(&quot;DATABASE_URL&quot;)
  )
  
  func main() {
      fmt.Printf(&quot;app_uri: %s\n&quot;, appURI)
      fmt.Printf(&quot;database_url: %s\n&quot;, databaseURL)
      sourcePath := fmt.Sprintf(&quot;file://%s/db/migrations&quot;, appURI)
      m, err := migrate.New(sourcePath, databaseURL)
      if err != nil {
          logger.Error(&quot;Failed to establish the connection of the migration.&quot;, err)
      }
      err = m.Up()
      if err != nil &amp;&amp; err.Error() == &quot;no change&quot; {
          fmt.Println(&quot;  &gt; NOTE: There is no change related to the operation of the migration.&quot;)
          return
      } else if err != nil {
          logger.Error(&quot;Failed to establish the connection of the migration.&quot;, err)
      }
      fmt.Println(&quot;  &gt; Done.&quot;)
  }
  </code></pre>
  <p>When I pushed the code to the heroku, I got the following error:</p>
  <pre><code>remote: -----&gt; Running bin/go-post-compile hook
  remote: app_uri: 
  remote: database_url: ?sslmode=require
  remote: panic: runtime error: invalid memory address or nil pointer dereference
  remote: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x503b06]
  remote: 
  </code></pre>
  <p>It seems that the process could not get the environment variables when it run the <code>go-post-compile</code> script.</p>
  <p>The process works well with the config vars after the buildpack compiles the application.</p>
  <p>So do you have any ideas?</p>