Take Path fragment from URL instead of whole URL.

This also makes better error handling in case a asset couldn't be found in the files map.
This commit is contained in:
Johannes 'fish' Ziemke 2013-04-09 12:12:24 +02:00
parent bf197baaf9
commit 17f622bd6e

View file

@ -3,6 +3,7 @@ package blob
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
@ -20,7 +21,11 @@ var mimeMap = map[string]string{
} }
func GetFile(bucket string, name string) ([]byte, error) { func GetFile(bucket string, name string) ([]byte, error) {
reader := bytes.NewReader(files[bucket][name]) blob, ok := files[bucket][name]
if !ok {
return nil, fmt.Errorf("Could not find %s/%s. Missing/updated files.go?", bucket, name)
}
reader := bytes.NewReader(blob)
gz, err := gzip.NewReader(reader) gz, err := gzip.NewReader(reader)
if err != nil { if err != nil {
return nil, err return nil, err
@ -36,7 +41,7 @@ func GetFile(bucket string, name string) ([]byte, error) {
type Handler struct{} type Handler struct{}
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
name := r.URL.String() name := r.URL.Path
if name == "" { if name == "" {
name = "index.html" name = "index.html"
} }