Skip to content

Commit 8bd5804

Browse files
committed
Fix todos
1 parent cf8b4e0 commit 8bd5804

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

site/embed.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package site
55

66
import (
77
"bytes"
8+
"context"
89
"embed"
910
"fmt"
1011
"io/fs"
@@ -88,7 +89,7 @@ func serveFiles(fileSystem fs.FS, logger slog.Logger) (http.HandlerFunc, error)
8889
fileBytes, err := fs.ReadFile(fileSystem, normalizedName)
8990

9091
if err != nil {
91-
// TODO: Log
92+
logger.Warn(context.Background(), "Unable to load file", slog.F("fileName", normalizedName))
9293
continue
9394
}
9495

@@ -100,7 +101,7 @@ func serveFiles(fileSystem fs.FS, logger slog.Logger) (http.HandlerFunc, error)
100101
continue
101102
}
102103

103-
// TODO: Log that we encountered a directory that we can't serve
104+
logger.Warn(context.Background(), "Serving from nested directories is not implemented", slog.F("name", name))
104105
}
105106

106107
if indexBytes == nil {
@@ -122,6 +123,7 @@ func serveFiles(fileSystem fs.FS, logger slog.Logger) (http.HandlerFunc, error)
122123
logger.Warn(request.Context(), "Unable to find request file", slog.F("fileName", normalizedFileName))
123124
fileBytes = indexBytes
124125
isCacheable = false
126+
normalizedFileName = "index.html"
125127
}
126128

127129
if isCacheable {
@@ -131,8 +133,7 @@ func serveFiles(fileSystem fs.FS, logger slog.Logger) (http.HandlerFunc, error)
131133
writer.Header().Add("Cache-Control", "public, max-age=31536000, immutable")
132134
}
133135

134-
// TODO: Proper name for content:
135-
http.ServeContent(writer, request, "", time.Time{}, bytes.NewReader(fileBytes))
136+
http.ServeContent(writer, request, normalizedFileName, time.Time{}, bytes.NewReader(fileBytes))
136137
}
137138

138139
return serveFunc, nil

0 commit comments

Comments
 (0)