enhanced prefix handling
This commit is contained in:
parent
dd14b201b1
commit
01030a52ba
1 changed files with 2 additions and 6 deletions
8
fs.go
8
fs.go
|
@ -65,16 +65,12 @@ func (fs *FS) ServeHTTP(w http.ResponseWriter, r *http.Request, info RoutingInfo
|
||||||
func (fs *FS) findFile(url string) (fs.File, error) {
|
func (fs *FS) findFile(url string) (fs.File, error) {
|
||||||
// build file path
|
// build file path
|
||||||
filePath := path.Join(fs.FolderPrefix, url)
|
filePath := path.Join(fs.FolderPrefix, url)
|
||||||
if strings.HasPrefix(filePath, "/") {
|
filePath = strings.TrimPrefix(filePath, "/")
|
||||||
filePath = filePath[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// check, if file exists in local folder
|
// check, if file exists in local folder
|
||||||
if fs.UseLocalFolder {
|
if fs.UseLocalFolder {
|
||||||
localFilePath := path.Join(fs.LocalFolderPrefix, filePath)
|
localFilePath := path.Join(fs.LocalFolderPrefix, filePath)
|
||||||
if strings.HasPrefix(localFilePath, "/") {
|
localFilePath = strings.TrimPrefix(localFilePath, "/")
|
||||||
localFilePath = localFilePath[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := os.Open(localFilePath)
|
file, err := os.Open(localFilePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue