mirror of https://github.com/jlelse/GoBlog
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
687 B
Go
33 lines
687 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"io/fs"
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
|
|
"go.goblog.app/app/pkgs/contenttype"
|
|
)
|
|
|
|
func (a *goBlog) serveFs(f fs.FS, basePath string) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
fileName := strings.TrimPrefix(r.URL.Path, basePath)
|
|
file, err := f.Open(fileName)
|
|
if err != nil {
|
|
a.serve404(w, r)
|
|
return
|
|
}
|
|
switch path.Ext(fileName) {
|
|
case ".js":
|
|
w.Header().Set(contentType, contenttype.JSUTF8)
|
|
_ = a.min.Get().Minify(contenttype.JS, w, file)
|
|
case ".css":
|
|
w.Header().Set(contentType, contenttype.CSSUTF8)
|
|
_ = a.min.Get().Minify(contenttype.CSS, w, file)
|
|
default:
|
|
_, _ = io.Copy(w, file)
|
|
}
|
|
}
|
|
}
|