Ejemplo n.º 1
0
func EmbeddedCheck(wc *config.WebConf) func(r *http.Request, rm *mux.RouteMatch) bool {
	return func(r *http.Request, rm *mux.RouteMatch) bool {
		asset := EmbeddedAssetPath(wc, r.URL.Path)
		fmt.Printf("Finding resrouce: %s\n", asset)
		fileBytes, err := wc.EmbeddedAsset(asset)
		exists := err == nil && fileBytes != nil && len(fileBytes) > 0
		return exists
	}
}
Ejemplo n.º 2
0
func ServeEmbedded(wc *config.WebConf) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		asset := EmbeddedAssetPath(wc, r.URL.Path)
		filebytes, err := wc.EmbeddedAsset(asset)
		if err != nil {
			log.Printf("Didn't find embedded asset: %s\n", asset)
			http.NotFound(w, r)
			return
		}

		ext := filepath.Ext(r.URL.Path)
		mime, err := MimeType(ext)
		if err != nil {
			log.Printf("Didn't find extention: %s\n", ext)
			http.NotFound(w, r)
			return
		}

		w.Header().Set("Cache-Control", "public, max-age=315360000")
		w.Header().Set("Content-Type", mime)
		w.Write(filebytes)
	}
}