// +build dev package main import ( "flag" "net/http" "os" "path/filepath" ) var StaticDir string = "static/" func init() { mux.Handle("/css/", http.FileServer(http.Dir(StaticDir))) mux.Handle("/js/", http.FileServer(http.Dir(StaticDir))) flag.StringVar(&StaticDir, "static", StaticDir, "Directory containing static files") } func serveStaticAsset(w http.ResponseWriter, r *http.Request, url string) { if url == "index.html" { r.URL.Path = "/" } else { r.URL.Path = "/" + url } http.FileServer(http.Dir(StaticDir)).ServeHTTP(w, r) } func sanitizeStaticOptions() error { StaticDir, _ := filepath.Abs("static") if _, err := os.Stat(StaticDir); os.IsNotExist(err) { StaticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static")) if _, err := os.Stat(StaticDir); os.IsNotExist(err) { return err } } return nil }