static/static_route.go

19 lines
332 B
Go
Raw Permalink Normal View History

2025-01-12 11:01:29 +00:00
package static
import (
"net/http"
"strings"
)
func (s Static) StaticRoute(w http.ResponseWriter, r *http.Request) {
f, err := s.FS.ReadFile(s.prefix + r.PathValue("filename"))
if strings.HasSuffix(r.URL.Path, ".css") {
w.Header().Set("Content-Type", "text/css")
}
if err != nil {
Err404(w, r)
return
}
w.Write(f)
}