From afd792feb567f0848ddc05f6a90a7b7672fe4974 Mon Sep 17 00:00:00 2001 From: Alex Studer Date: Wed, 20 Oct 2021 19:18:03 +0000 Subject: [PATCH] net/http: mention io.Seeker requirement in FS documentation Both FileServer and NewFileTransport can try to seek a file, specifically when MIME type sniffing is performed. This can be somewhat surprising to an implementer of an fs.FS, as their filesystem will appear to work until a user tries to access a file with an unrecognized extension (which requires type sniffing and therefore seeking). With FileServer, this results in a "seeker can't seek" message, which is not very clear for the developer. The issue arises because fs.FS does not require Seek, while http.FileSystem does. Therefore, this change adds a line to the documentation of net/http's adapter function mentioning the requirement. Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a GitHub-Last-Rev: fddccdae36e04fcb87d78b3b03fa4658dbb7d83d GitHub-Pull-Request: golang/go#48781 Reviewed-on: https://go-review.googlesource.com/c/go/+/353874 Reviewed-by: Damien Neil Auto-Submit: Damien Neil Run-TryBot: Damien Neil TryBot-Result: Gopher Robot Reviewed-by: David Chase --- src/net/http/fs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/net/http/fs.go b/src/net/http/fs.go index 4f144ebad2..87caeb7e90 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -818,6 +818,7 @@ func (f ioFile) Readdir(count int) ([]fs.FileInfo, error) { // FS converts fsys to a FileSystem implementation, // for use with FileServer and NewFileTransport. +// The files provided by fsys must implement io.Seeker. func FS(fsys fs.FS) FileSystem { return ioFS{fsys} } -- 2.50.0