title: How to call a funcion after success
body: <p>I want to call a function (<code>os.Remove</code>) after successfully uploading a file.</p>
  <p>I'm trying to make a one time file download endpoint which deletes the file right after it's upload.</p>
  <p>Can I call the function just after <code>w.Write(data)</code>? What if the upload will not succeed?</p>
  <p>My handler looks something like this:</p>
  <pre><code>func oneTimeFileDownloadHandler(w http.ResponseWriter, r *http.Request) {
      filename, mimetype, data := getFile(r)
      w.Header().Set(&quot;Content-Disposition&quot;, fmt.Sprintf(`attachment;filename=&quot;%s&quot;`, filename))
      w.Header().Set(&quot;Content-Type&quot;, mimetype)
      if _, err := w.Write(data); err != nil {
          http.Error(w, fmt.Sprintf(&quot;error writing download data: %s&quot;, err), http.StatusInternalServerError)
          return
      }
      os.Remove(filename)
  }
  </code></pre>