static/static_route.go
2025-01-12 04:01:29 -07:00

18 lines
332 B
Go

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