Documentation
¶
Overview ¶
Package modtimefs wraps fs.FS with fake ModTime. embed.FS always returns a zero value of time.Time for ModTime(), so the Last-Modified is not added to the response header when embed.FS is used with http.FileServer and http.FS. This package can be avoid this with user specific ModTime. The file in original fs.FS must implement io.Seeker to use with http.FileServer.
Example ¶
package main import ( "embed" "fmt" "net/http" "net/http/httptest" "time" "github.com/johejo/modtimefs" ) //go:embed testdata/* var testdata embed.FS func main() { rec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/testdata/hello.txt", nil) fsys := modtimefs.New(testdata, time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)) http.FileServer(http.FS(fsys)).ServeHTTP(rec, req) resp := rec.Result() fmt.Println(resp.Header.Get("Last-Modified")) }
Output: Sun, 01 Jan 2023 00:00:00 GMT
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.