2022-02-08 18:58:19 +00:00
|
|
|
package overlays
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Compile-time assertion
|
|
|
|
var _ http.FileSystem = httpFSStack{}
|
|
|
|
|
|
|
|
type httpFSStack []http.FileSystem
|
|
|
|
|
|
|
|
func (h httpFSStack) Open(name string) (http.File, error) {
|
2024-01-01 16:52:18 +00:00
|
|
|
for _, stackedFS := range h {
|
|
|
|
if f, err := stackedFS.Open(name); err == nil {
|
2022-02-08 18:58:19 +00:00
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fs.ErrNotExist
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile-time assertion
|
|
|
|
var _ http.FileSystem = prefixedFS{}
|
|
|
|
|
|
|
|
type prefixedFS struct {
|
|
|
|
originFS http.FileSystem
|
|
|
|
prefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newPrefixedFS(prefix string, originFS http.FileSystem) *prefixedFS {
|
|
|
|
return &prefixedFS{originFS: originFS, prefix: prefix}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p prefixedFS) Open(name string) (http.File, error) {
|
2024-01-01 16:52:18 +00:00
|
|
|
return p.originFS.Open(path.Join(p.prefix, name)) //nolint:wrapcheck
|
2022-02-08 18:58:19 +00:00
|
|
|
}
|