Documentation
¶
Overview ¶
Package vcstime provides a file system wrapper that gives embedded files a meaningful modification time.
embed.FS stores and serves no ModTime: files report a zero fs.FileInfo.ModTime, which disables HTTP caching semantics when served with net/http: no Last-Modified header is sent and If-Modified-Since requests are never answered with a 304. vcstime derives a modification time from the vcs.time build setting recorded by the go command (see "go version -m" or debug.BuildInfo), enabling [http.FS] to provide working cache headers for clean builds.
FS wraps an fs.FS (typically an embed.FS) and reports that time as the modification time of every file that does not have a real timestamp of its own. Usage:
//go:embed internal/whatever/*.*
var content embed.FS
mux.Handle("/", http.FileServer(http.FS(vcstime.FS(content))))
vcs.time is the commit time of the revision that was built, not the wall-clock build time: the two coincide for clean CI builds, but a tree with local modifications yields an older commit time. Binaries built without VCS stamping (for example with -buildvcs=false) have no vcs.time, and FS then behaves exactly like the file system it wraps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FS ¶
FS returns an fs.FS that serves files from fsys, reporting ModTime as the modification time of any file that has no real timestamp of its own.
It is intended for wrapping an embed.FS, whose files always report a zero ModTime. Files that already have a real timestamp (for example in an [fstest.MapFS] or os-backed file system) are passed through unchanged, so it is always safe to wrap.
If the binary carries no vcs.time stamp, fsys itself is returned unchanged.
Types ¶
This section is empty.