Skip to content

Instantly share code, notes, and snippets.

@artyom
Last active March 7, 2016 08:11
Show Gist options
  • Select an option

  • Save artyom/d084cbf0c143ff4ced32 to your computer and use it in GitHub Desktop.

Select an option

Save artyom/d084cbf0c143ff4ced32 to your computer and use it in GitHub Desktop.
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() {
assets := "Archive.zip"
bind := "127.0.0.1:8080"
flag.StringVar(&assets, "f", assets, "path to `zipfile`")
flag.StringVar(&bind, "l", bind, "address to listen")
flag.Parse()
zr, err := zip.OpenReader(assets)
if err != nil {
log.Fatal(err)
}
defer zr.Close()
vfs := zipfs.New(zr, "/")
fs := httpfs.New(vfs)
http.Handle("/", http.RedirectHandler("/static/", 301))
http.Handle("/static/", http.FileServer(fs))
log.Fatal(http.ListenAndServe(bind, nil))
}
func init() { log.SetFlags(log.Lshortfile) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment