title: go - serve contents from a zip file in http
body: <p>i'm looking at <code>github.com/remyoudompheng/go-misc/zipfs</code> to serve content from a zip file in http.</p>
  
  <p>this minimal example works, i can get a {FILE} contained in <strong>files/archives.zip</strong>:
    <strong><code>http://localhost:8080/zip/{FILE}</code></strong></p>
  
  <pre><code>package main
  
  import (
      "archive/zip"
      "github.com/remyoudompheng/go-misc/zipfs"
      "log"
      "net/http"
  )
  
  func main() {
  
      z, err := zip.OpenReader("files/archive.zip")
      if err != nil {
          log.Fatal(err)
      }
      defer z.Close()
  
      http.Handle("/zip/", http.StripPrefix("/zip/", http.FileServer(zipfs.NewZipFS(&amp;z.Reader))))
      log.Fatal(http.ListenAndServe(":8080", nil))
  }
  </code></pre>
  
  <p>now, suppose that i want something like <strong><code>http://localhost:8080/zip/{ZIPFILE}/{FILE}</code></strong><br>
  i'm trying registering a func but doesn't work</p>
  
  <pre><code>package main
  
  import (
      "archive/zip"
      "github.com/remyoudompheng/go-misc/zipfs"
      "html"
      "log"
      "net/http"
      "strings"
  )
  
  func servezip(res http.ResponseWriter, req *http.Request) {
      zippath := "files/" + strings.Split(html.EscapeString(req.URL.Path), "/")[2] + ".zip"
  
      z, err := zip.OpenReader(zippath)
      if err != nil {
          http.Error(res, err.Error(), 404)
          return
      }
      defer z.Close()
      http.StripPrefix("/zip/", http.FileServer(zipfs.NewZipFS(&amp;z.Reader)))
  }
  
  func main() {
      http.HandleFunc("/zip/", servezip)
      log.Fatal(http.ListenAndServe(":8080", nil))
  }
  </code></pre>
  
  <p>what i'm missing? can an handlefunc return an http.fileserver?</p>