I embedded a file like this:
package main
import (
"fmt"
"embed"
"net/http"
)
//go:embed test.txt
var fs embed.FS
func main() {
f, _ := fs.Open("test.txt")
fi, _ := f.Stat()
fmt.Println(fi.ModTime()) // 0001-01-01 00:00:00 +0000 UTC
// With Last-Modified header
http.Handle("/dir/", http.StripPrefix("/dir/", http.FileServer(http.Dir("."))))
// Without Last-Modified header -> easy to circumvent, but not suitable as drop-in replacement
http.Handle("/embed/", http.StripPrefix("/embed/", http.FileServer(http.FS(fs))))
http.ListenAndServe(":8080", nil)
}
I expected fi.ModTime
to return the file’s modification time at the time it was embedded.
time.Time{}
is returned instead (https://golang.org/src/embed/embed.go#229). The above program includes an example of when this becomes relevant. Please help me understand this design decision.