diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-18 08:43:03 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-18 08:43:03 -0700 |
| commit | 81c25beb38c87678a52145ef8fcb97631bfa8322 (patch) | |
| tree | 32795cfe5bf882171e4fc3f590931a0d5f507b03 /roseh.moe.go | |
| parent | Use ReadTimeout. (diff) | |
| download | roseh.moe-81c25beb38c87678a52145ef8fcb97631bfa8322.tar.zst | |
Use http.ServeContent
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 9 |
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() { |
