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

11
pkg.go
View file

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