summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-10-18 08:43:03 -0700
committerRose Hogenson <rosehogenson@posteo.net>2024-10-18 08:43:03 -0700
commit81c25beb38c87678a52145ef8fcb97631bfa8322 (patch)
tree32795cfe5bf882171e4fc3f590931a0d5f507b03
parent0cca0dd2e15c5d596f855bef40f22a9a06d5453a (diff)
downloadroseh.moe-81c25beb38c87678a52145ef8fcb97631bfa8322.tar.zst
Use http.ServeContent
-rw-r--r--roseh.moe.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 0556269..ce66f73 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -17,6 +17,8 @@ import (
var (
port = flag.Int("port", 42069, "port to listen on")
https = flag.Bool("https", false, "use https")
+
+ serverStartTime = time.Now()
)
//go:embed templates/404.html.template
@@ -49,15 +51,14 @@ func index(w http.ResponseWriter, _ *http.Request) {
var staticFiles embed.FS
func static(w http.ResponseWriter, r *http.Request) {
- f, err := staticFiles.Open(strings.TrimPrefix(r.URL.Path, "/"))
+ fileName := strings.TrimPrefix(r.URL.Path, "/")
+ f, err := staticFiles.Open(fileName)
if err != nil {
notFound(w, r)
return
}
defer f.Close()
- if _, err := io.Copy(w, f); err != nil {
- log.Printf("Warning: static: %s", err)
- }
+ http.ServeContent(w, r, fileName, serverStartTime, f.(io.ReadSeeker))
}
func main() {