youp0m/static.go

37 lines
805 B
Go

// +build !dev
package main
import (
"net/http"
"path"
)
//go:generate go-bindata -ignore "\\.go|\\.less" -pkg "main" -o "bindata.go" static/...
//go:generate go fmt bindata.go
const StaticDir string = "./static/"
func init() {
mux.HandleFunc("/css/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
serveStaticAsset(w, r, r.URL.Path)
})
mux.HandleFunc("/js/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/javascript")
serveStaticAsset(w, r, r.URL.Path)
})
}
func serveStaticAsset(w http.ResponseWriter, r *http.Request, url string) {
if data, err := Asset(path.Join(StaticDir, url)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
}
func sanitizeStaticOptions() error {
return nil
}