Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
687 B

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)
}
}
}