Skip to content

Instantly share code, notes, and snippets.

@namsral
Last active October 16, 2017 10:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namsral/dd92a011b9195d25ccf8 to your computer and use it in GitHub Desktop.
Save namsral/dd92a011b9195d25ccf8 to your computer and use it in GitHub Desktop.
Deploy and serve assets from a zip archive
package main
import (
"archive/zip"
"flag"
"log"
"net/http"
"golang.org/x/tools/godoc/vfs/httpfs"
"golang.org/x/tools/godoc/vfs/zipfs"
)
func main() {
zipPath := flag.String("zip", "assets.zip", "zip file containing assets")
httpAddr := flag.String("http", "localhost:6011", "http address")
flag.Parse()
r, err := zip.OpenReader(*zipPath)
if err != nil {
log.Fatal(err)
}
fs := zipfs.New(r, *zipPath)
m := http.NewServeMux()
m.Handle("/assets/", http.FileServer(httpfs.New(fs)))
log.Print("Listening on ", *httpAddr)
if err := http.ListenAndServe(*httpAddr, m); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment