Last active
March 7, 2016 08:11
-
-
Save artyom/d084cbf0c143ff4ced32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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