-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file server implementation (#3588)
So that it doesn't require introducing a `Replace` function. The new implementation is more robust and properly handles cases where the file path is deep and differs from the mount path.
- Loading branch information
Showing
7 changed files
with
72 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// appendFS is a custom implementation of fs.FS that appends a specified prefix | ||
// to the file paths before delegating the Open call to the underlying fs.FS. | ||
type appendFS struct { | ||
prefix string | ||
fs http.FileSystem | ||
} | ||
|
||
// Open opens the named file, appending the prefix to the file path before | ||
// passing it to the underlying fs.FS. | ||
func (s appendFS) Open(name string) (http.File, error) { | ||
return s.fs.Open(path.Join(s.prefix, name)) | ||
} | ||
|
||
// appendPrefix returns a new fs.FS that appends the specified prefix to file paths | ||
// before delegating to the provided embed.FS. | ||
func appendPrefix(fsys http.FileSystem, prefix string) http.FileSystem { | ||
return appendFS{prefix: prefix, fs: fsys} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.