From 63f484e269e99648cb2a9c6a57ae7c83eadc6765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 6 Mar 2025 07:01:18 +0100 Subject: [PATCH] Honor the useStaticDirectory variable in the static handler to minimize unnecessary os.Stat --- pkg.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg.go b/pkg.go index a5baa56..3f1647c 100644 --- a/pkg.go +++ b/pkg.go @@ -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) }