From 80f5699d370cdfc62bd818fa7ba5a22babf6b521 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Mon, 19 Sep 2022 01:20:23 +0300 Subject: [PATCH] minor: HandleDir: godoc --- core/router/api_builder.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/router/api_builder.go b/core/router/api_builder.go index 07c0ca92..cb1b2028 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -620,6 +620,14 @@ func (api *APIBuilder) HandleMany(methodOrMulti string, relativePathorMulti stri // Usage: // HandleDir("/public", "./assets", DirOptions{...}) or // HandleDir("/public", iris.Dir("./assets"), DirOptions{...}) +// OR +// //go:embed assets/* +// var filesystem embed.FS +// HandleDir("/public",filesystem, DirOptions{...}) +// OR to pick a specific folder of the embedded filesystem: +// import "io/fs" +// subFilesystem, err := fs.Sub(filesystem, "assets") +// HandleDir("/public",subFilesystem, DirOptions{...}) // // Examples: // https://github.com/kataras/iris/tree/master/_examples/file-server @@ -650,8 +658,10 @@ func (api *APIBuilder) HandleDir(requestPath string, fsOrDir interface{}, opts . panic(err) } fs = http.FS(subfs) + case stdfs.FS: + fs = http.FS(v) default: - panic(fmt.Errorf(`unexpected "fsOrDir" argument type of %T (string or http.FileSystem)`, v)) + panic(fmt.Sprintf(`HandleDir: unexpected "fsOrDir" argument type of %T (string or http.FileSystem)`, v)) } h := FileServer(fs, options)