1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +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:
Gerasimos (Makis) Maropoulos
2020-07-24 13:03:49 +03:00
parent d697426cb6
commit c3205dafa1
58 changed files with 2581 additions and 9855 deletions

View File

@@ -12,11 +12,11 @@ func newApp() *iris.Application {
// first parameter is the request path
// second is the system directory
//
// app.HandleDir("/css", "./assets/css")
// app.HandleDir("/js", "./assets/js")
// app.HandleDir("/css", iris.Dir("./assets/css"))
// app.HandleDir("/js", iris.Dir("./assets/js"))
v1 := app.Party("/v1")
v1.HandleDir("/static", "./assets", iris.DirOptions{
v1.HandleDir("/static", iris.Dir("./assets"), iris.DirOptions{
// Defaults to "/index.html", if request path is ending with **/*/$IndexName
// then it redirects to **/*(/) which another handler is handling it,
// that another handler, called index handler, is auto-registered by the framework
@@ -26,7 +26,19 @@ func newApp() *iris.Application {
Compress: false,
// List the files inside the current requested directory if `IndexName` not found.
ShowList: false,
// If `ShowList` is true then this function will be used instead of the default one to show the list of files of a current requested directory(dir).
Cache: iris.DirCacheOptions{
// enable in-memory cache and pre-compress the files.
Enable: true,
// ignore image types (and pdf).
CompressIgnore: iris.MatchImagesAssets,
// do not compress files smaller than size.
CompressMinSize: 300,
// available encodings that will be negotiated with client's needs.
Encodings: []string{"gzip", "br" /* you can also add: deflate, snappy */},
},
DirList: iris.DirListRich(),
// If `ShowList` is true then this function will be used instead of the default
// one to show the list of files of a current requested directory(dir).
// DirList: func(ctx iris.Context, dirName string, dir http.File) error { ... }
//
// Optional validator that loops through each requested resource.