|
|
|
@ -6,6 +6,7 @@ import (
|
|
|
|
|
"io"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -13,6 +14,11 @@ const (
|
|
|
|
|
StaticFiles = "static"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var mimeMap = map[string]string{
|
|
|
|
|
"css": "text/css",
|
|
|
|
|
"js": "text/javascript",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetFile(bucket string, name string) ([]byte, error) {
|
|
|
|
|
reader := bytes.NewReader(files[bucket][name])
|
|
|
|
|
gz, err := gzip.NewReader(reader)
|
|
|
|
@ -43,6 +49,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.Header().Set("Content-Type", http.DetectContentType(file))
|
|
|
|
|
contentType := http.DetectContentType(file)
|
|
|
|
|
if strings.Contains(contentType, "text/plain") || strings.Contains(contentType, "application/octet-stream") {
|
|
|
|
|
parts := strings.Split(name, ".")
|
|
|
|
|
contentType = mimeMap[parts[len(parts)-1]]
|
|
|
|
|
}
|
|
|
|
|
w.Header().Set("Content-Type", contentType)
|
|
|
|
|
w.Write(file)
|
|
|
|
|
}
|
|
|
|
|