diff options
Diffstat (limited to 'cmd/web/handlers/fs.go')
| -rw-r--r-- | cmd/web/handlers/fs.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cmd/web/handlers/fs.go b/cmd/web/handlers/fs.go index 629a7e1..aa6bbc5 100644 --- a/cmd/web/handlers/fs.go +++ b/cmd/web/handlers/fs.go @@ -2,6 +2,7 @@ package handlers import ( "encoding/json" + "io" "log" "net/http" "os" @@ -42,7 +43,15 @@ func (ctx *fsContext) get(w http.ResponseWriter, r *http.Request) { } defer root.Close() - file, err := root.ReadFile(name) + file, err := root.Open(name) + if err != nil { + ctx.err.Print(err.Error()) + http.Error(w, "Internal Server Error", 500) + return + } + defer file.Close() + + content, err := io.ReadAll(file) if err != nil { ctx.err.Print(err.Error()) http.Error(w, "Internal Server Error", 500) @@ -64,5 +73,5 @@ func (ctx *fsContext) get(w http.ResponseWriter, r *http.Request) { } } - w.Write(file) + w.Write(content) } |
