Honor the useStaticDirectory variable in the static handler to minimize unnecessary os.Stat

This commit is contained in:
Magnus Åhall 2025-03-06 07:01:18 +01:00
parent 1cf9318bc8
commit 63f484e269

5
pkg.go
View file

@ -305,12 +305,17 @@ func (service *Service) StaticHandler(w http.ResponseWriter, r *http.Request, se
r.URL.Path = fmt.Sprintf("/%s/%s", comp[1], comp[2]) r.URL.Path = fmt.Sprintf("/%s/%s", comp[1], comp[2])
p := fmt.Sprintf(service.staticDirectory+"/%s/%s", comp[1], comp[2]) p := fmt.Sprintf(service.staticDirectory+"/%s/%s", comp[1], comp[2])
if service.useStaticDirectory {
_, err = os.Stat(p) _, err = os.Stat(p)
if err == nil { if err == nil {
service.staticLocalFileserver.ServeHTTP(w, r) service.staticLocalFileserver.ServeHTTP(w, r)
} else { } else {
service.staticEmbeddedFileserver.ServeHTTP(w, r) service.staticEmbeddedFileserver.ServeHTTP(w, r)
} }
} else {
service.staticEmbeddedFileserver.ServeHTTP(w, r)
}
return return
} }