예제 #1
0
func loadBG() (image.Image, error) {
	byt, err := data.Asset("img/bg.jpg")
	if err != nil {
		return nil, fmt.Errorf("error loading background image: %s", err)
	}
	return jpeg.Decode(bytes.NewReader(byt))
}
예제 #2
0
func serveAsset(fpath string, w http.ResponseWriter, r *http.Request) {
	b, err := data.Asset(fpath)
	if err != nil {
		log.Printf("serveAsset: could not load asset data %s: %s", fpath, err)
		http.Error(w, "", http.StatusNotFound)
		return
	}

	finfo, err := data.AssetInfo(fpath)
	if err != nil {
		log.Printf("serveAsset: could not load asset fileinfo %s: %s", fpath, err)
		http.Error(w, "", http.StatusNotFound)
		return
	}
	http.ServeContent(w, r, finfo.Name(), finfo.ModTime(), bytes.NewReader(b))
}