Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created October 16, 2014 16:53
Show Gist options
  • Save spheromak/bb8c591689e8c5f8aaac to your computer and use it in GitHub Desktop.
Save spheromak/bb8c591689e8c5f8aaac to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"github.com/elazarl/go-bindata-assetfs"
)
// staticHanlder handles all requessts by returning the index.html
func staticHandler(w http.ResponseWriter, r *http.Request) {
data, err := Asset("data/index.html")
if err != nil {
log.Fatal("error while reading embedded data for 'index.html'")
}
w.Write(data)
}
func main() {
// register the packed data in pics to /pics
http.Handle("/pics/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "data"}))
// everthing else served by staticHandler (index.html)
http.HandleFunc("/", staticHandler)
// serve
http.ListenAndServe(":9089", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment