mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
New DirOptions.Cache field for in-memory caching and pre-compression for the fastest possible static file server
Read HISTORY.md it contains a breaking change, second parameter of HandleDir should be iris.Dir(...) instead of just a string relative to: https://github.com/kataras/iris/issues/1556#issuecomment-661057446 Former-commit-id: 14b48a06fb3b99287dff543932be2937a64233b9
This commit is contained in:
@@ -383,21 +383,28 @@ func (api *APIBuilder) HandleMany(methodOrMulti string, relativePathorMulti stri
|
||||
// with the contents of a file system (physical or embedded).
|
||||
//
|
||||
// first parameter : the route path
|
||||
// second parameter : the system or the embedded directory that needs to be served
|
||||
// third parameter : not required, the directory options, set fields is optional.
|
||||
// second parameter : the file system needs to be served
|
||||
// third parameter : not required, the serve directory options.
|
||||
//
|
||||
// Alternatively, to get just the handler for that look the FileServer function instead.
|
||||
//
|
||||
// api.HandleDir("/static", "./assets", DirOptions {ShowList: true, Gzip: true, IndexName: "index.html"})
|
||||
// api.HandleDir("/static", iris.Dir("./assets"), iris.DirOptions{IndexName: "/index.html", Compress: true})
|
||||
//
|
||||
// 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, directory string, opts ...DirOptions) (routes []*Route) {
|
||||
options := getDirOptions(opts...)
|
||||
func (api *APIBuilder) HandleDir(requestPath string, fs http.FileSystem, opts ...DirOptions) (routes []*Route) {
|
||||
options := DefaultDirOptions
|
||||
if len(opts) > 0 {
|
||||
options = opts[0]
|
||||
}
|
||||
|
||||
h := FileServer(fs, options)
|
||||
description := "file server"
|
||||
if d, ok := fs.(http.Dir); ok {
|
||||
description = string(d)
|
||||
}
|
||||
|
||||
h := FileServer(directory, options)
|
||||
description := directory
|
||||
fileName, lineNumber := context.HandlerFileLine(h) // take those before StripPrefix.
|
||||
|
||||
// if subdomain, we get the full path of the path only,
|
||||
|
||||
1116
core/router/fs.go
1116
core/router/fs.go
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"github.com/kataras/iris/v12/core/errgroup"
|
||||
"github.com/kataras/iris/v12/macro"
|
||||
@@ -149,20 +151,17 @@ type Party interface {
|
||||
// with the contents of a file system (physical or embedded).
|
||||
//
|
||||
// first parameter : the route path
|
||||
// second parameter : the system or the embedded directory that needs to be served
|
||||
// third parameter : not required, the directory options, set fields is optional.
|
||||
// second parameter : the file system needs to be served
|
||||
// third parameter : not required, the serve directory options.
|
||||
//
|
||||
// Alternatively, to get just the handler for that look the FileServer function instead.
|
||||
//
|
||||
// api.HandleDir("/static", "./assets", DirOptions {
|
||||
// ShowList: true,
|
||||
// Compress: true,
|
||||
// IndexName: "index.html"})
|
||||
// api.HandleDir("/static", iris.Dir("./assets"), iris.DirOptions{IndexName: "/index.html", Compress: true})
|
||||
//
|
||||
// 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
|
||||
HandleDir(requestPath, directory string, opts ...DirOptions) []*Route
|
||||
HandleDir(requestPath string, fs http.FileSystem, opts ...DirOptions) []*Route
|
||||
|
||||
// None registers an "offline" route
|
||||
// see context.ExecRoute(routeName) and
|
||||
|
||||
Reference in New Issue
Block a user