static/wrap_static.go

23 lines
410 B
Go
Raw Permalink Normal View History

2025-01-12 11:01:29 +00:00
package static
import (
"fmt"
"net/http"
)
func (s Static) WrapStatic(url string, truefile string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != url {
fmt.Println("404: " + r.URL.Path)
Err404(w, r)
return
}
f, err := s.FS.ReadFile(s.prefix + truefile)
if err != nil {
Err404(w, r)
return
}
w.Write(f)
}
}