mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
Full support of the http.FileSystem on all view engines as requested at #1575
Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
This commit is contained in:
@@ -475,13 +475,28 @@ func (api *APIBuilder) HandleMany(methodOrMulti string, relativePathorMulti stri
|
||||
//
|
||||
// Returns all the registered routes, including GET index and path patterm and HEAD.
|
||||
//
|
||||
// Examples can be found at: https://github.com/kataras/iris/tree/master/_examples/file-server
|
||||
func (api *APIBuilder) HandleDir(requestPath string, fs http.FileSystem, opts ...DirOptions) (routes []*Route) {
|
||||
// Usage:
|
||||
// HandleDir("/public", "./assets", DirOptions{...}) or
|
||||
// HandleDir("/public", iris.Dir("./assets"), DirOptions{...})
|
||||
//
|
||||
// Examples:
|
||||
// https://github.com/kataras/iris/tree/master/_examples/file-server
|
||||
func (api *APIBuilder) HandleDir(requestPath string, fsOrDir interface{}, opts ...DirOptions) (routes []*Route) {
|
||||
options := DefaultDirOptions
|
||||
if len(opts) > 0 {
|
||||
options = opts[0]
|
||||
}
|
||||
|
||||
var fs http.FileSystem
|
||||
switch v := fsOrDir.(type) {
|
||||
case string:
|
||||
fs = http.Dir(v)
|
||||
case http.FileSystem:
|
||||
fs = v
|
||||
default:
|
||||
panic(fmt.Errorf(`unexpected "fsOrDir" argument type of %T (string or http.FileSystem)`, v))
|
||||
}
|
||||
|
||||
h := FileServer(fs, options)
|
||||
description := "file server"
|
||||
if d, ok := fs.(http.Dir); ok {
|
||||
|
||||
Reference in New Issue
Block a user