mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
add support for embed.FS
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
stdfs "io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -633,6 +635,21 @@ func (api *APIBuilder) HandleDir(requestPath string, fsOrDir interface{}, opts .
|
||||
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)
|
||||
default:
|
||||
panic(fmt.Errorf(`unexpected "fsOrDir" argument type of %T (string or http.FileSystem)`, v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user