diff options
| author | Julian Hurst <ark@mansus.space> | 2025-01-23 13:43:54 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2025-01-23 13:43:54 +0100 |
| commit | 392b9171e794446f596c75687f6fa5d76fb4cddd (patch) | |
| tree | 76e17b5aa220b072096b2de8d795023512989927 | |
| parent | 694235d8492726c28b7849f80410ddebf9fcbedc (diff) | |
| download | box-392b9171e794446f596c75687f6fa5d76fb4cddd.tar.gz | |
Use ServeFile instead of io.Copy
| -rw-r--r-- | main.go | 9 |
1 files changed, 1 insertions, 8 deletions
@@ -49,14 +49,7 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { serve(w, handler.token, "templates/index.html") } else { resourceId := path.Base(r.URL.Path) - f, err := os.Open(filepath.Join(handler.dataPath, resourceId)) - if err != nil { - log.Println(err) - w.WriteHeader(http.StatusBadRequest) - fmt.Fprint(w, err.Error()) - return - } - io.Copy(w, f) + http.ServeFile(w, r, filepath.Join(handler.dataPath, resourceId)) } return case http.MethodDelete: |
