mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
use the global function of context.ResolveFS on APIBuilder.HandleDir (see prev commit)
This commit is contained in:
parent
95a8110f1e
commit
fd1db640a0
|
@ -1,10 +1,8 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
stdfs "io/fs"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -637,33 +635,7 @@ func (api *APIBuilder) HandleDir(requestPath string, fsOrDir interface{}, opts .
|
||||||
options = opts[0]
|
options = opts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs http.FileSystem
|
fs := context.ResolveFS(fsOrDir)
|
||||||
switch v := fsOrDir.(type) {
|
|
||||||
case string:
|
|
||||||
fs = http.Dir(v)
|
|
||||||
case http.FileSystem:
|
|
||||||
fs = v
|
|
||||||
case embed.FS:
|
|
||||||
direEtries, err := v.ReadDir(".")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(direEtries) == 0 {
|
|
||||||
panic("HandleDir: no directories found under the embedded file system")
|
|
||||||
}
|
|
||||||
|
|
||||||
subfs, err := stdfs.Sub(v, direEtries[0].Name())
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fs = http.FS(subfs)
|
|
||||||
case stdfs.FS:
|
|
||||||
fs = http.FS(v)
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf(`HandleDir: unexpected "fsOrDir" argument type of %T (string or http.FileSystem)`, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
h := FileServer(fs, options)
|
h := FileServer(fs, options)
|
||||||
description := "file server"
|
description := "file server"
|
||||||
if d, ok := fs.(http.Dir); ok {
|
if d, ok := fs.(http.Dir); ok {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user