Skip to content

Commit

Permalink
Full support of the http.FileSystem on all view engines as requested at
Browse files Browse the repository at this point in the history
#1575

Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
  • Loading branch information
kataras committed Sep 5, 2020
1 parent 7e6d453 commit e1f25eb
Show file tree
Hide file tree
Showing 50 changed files with 1,603 additions and 1,216 deletions.
5 changes: 4 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ Response:

Other Improvements:

- Full `http.FileSystem` interface support for all **view** engines as [requested](https://github.com/kataras/iris/issues/1575). The first argument of the functions(`HTML`, `Blocks`, `Pug`, `Amber`, `Ace`, `Jet`, `Django`, `Handlebars`) can now be either a directory of `string` type (like before) or a value which completes the `http.FileSystem` interface. The `.Binary` method of all view engines was removed: pass the go-bindata's latest version `AssetFile()` exported function as the first argument instead of string.

- Add `Route.ExcludeSitemap() *Route` to exclude a route from sitemap as requested in [chat](https://chat.iris-go.com), also offline routes are excluded automatically now.

- Improved tracing (with `app.Logger().SetLevel("debug")`) for routes. Screens:
Expand Down Expand Up @@ -641,6 +643,7 @@ New Context Methods:

Breaking Changes:

- The `.Binary` method of all view engines was removed: pass the go-bindata's latest version `AssetFile()` exported function as the first argument instead of string. All examples updated.
- `ContextUploadFormFiles(destDirectory string, before ...func(*Context, *multipart.FileHeader) bool) (uploaded []*multipart.FileHeader, n int64, err error)` now returns the total files uploaded too (as its first parameter) and the "before" variadic option should return a boolean, if false then the specific file is skipped.
- `Context.PostValues(name string) ([]string, error)` now returns a second output argument of `error` type too, which reports `ErrEmptyForm` or `ErrNotFound` or `ErrEmptyFormField`. The single post value getters now returns the **last value** if multiple was given instead of the first one (this allows clients to append values on flow updates).
- `Party.GetReporter()` **removed**. The `Application.Build` returns the first error now and the API's errors are logged, this allows the server to run even if some of the routes are invalid but not fatal to the entire application (it was a request from a company).
Expand All @@ -652,7 +655,7 @@ Breaking Changes:
- `iris.Gzip` and `iris.GzipReader` replaced with `iris.Compression` (middleware).
- `ctx.ClientSupportsGzip() bool` replaced with `ctx.ClientSupportsEncoding("gzip", "br" ...) bool`.
- `ctx.GzipResponseWriter()` is **removed**.
- `Party.HandleDir/iris.FileServer` now accepts a `http.FileSystem` instead of a string and returns a list of `[]*Route` (GET and HEAD) instead of GET only. Write: `app.HandleDir("/", iris.Dir("./assets"))` instead of `app.HandleDir("/", "./assets")` and `DirOptions.Asset, AssetNames, AssetInfo` removed, use `go-bindata -fs [..]` and `app.HandleDir("/", AssetFile())` instead.
- `Party.HandleDir/iris.FileServer` now accepts both `http.FileSystem` and `string` and returns a list of `[]*Route` (GET and HEAD) instead of GET only. You can write: both `app.HandleDir("/", iris.Dir("./assets"))` and `app.HandleDir("/", "./assets")` and `DirOptions.Asset, AssetNames, AssetInfo` removed, use `go-bindata -fs [..]` and `app.HandleDir("/", AssetFile())` instead.
- `Context.OnClose` and `Context.OnCloseConnection` now both accept an `iris.Handler` instead of a simple `func()` as their callback.
- `Context.StreamWriter(writer func(w io.Writer) bool)` changed to `StreamWriter(writer func(w io.Writer) error) error` and it's now the `Context.Request().Context().Done()` channel that is used to receive any close connection/manual cancel signals, instead of the deprecated `ResponseWriter().CloseNotify()` one. Same for the `Context.OnClose` and `Context.OnCloseConnection` methods.
- Fixed handler's error response not be respected when response recorder was used instead of the common writer. Fixes [#1531](https://github.com/kataras/iris/issues/1531). It contains a **BREAKING CHANGE** of: the new `Configuration.ResetOnFireErrorCode` field should be set **to true** in order to behave as it used before this update (to reset the contents on recorder).
Expand Down
11 changes: 6 additions & 5 deletions _examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,16 @@
* [Write to a custom `io.Writer`](view/write-to)
* [Blocks](view/template_blocks_0)
* [Blocks Embedded](view/template_blocks_1_embedded)
* [Pug: Greeting](view/template_pug_0)
* [Pug: `Actions`](view/template_pug_1)
* [Pug: `Includes`](view/template_pug_2)
* [Pug: `Extends`](view/template_pug_3)
* [Jet Template](view/template_jet_0)
* [Pug: `Actions`](view/template_pug_0)
* [Pug: `Includes`](view/template_pug_1)
* [Pug Embedded`](view/template_pug_2_embedded)
* [Jet](view/template_jet_0)
* [Jet Embedded](view/template_jet_1_embedded)
* [Jet 'urlpath' tmpl func](view/template_jet_2)
* [Jet Template Funcs from Struct](view/template_jet_3)
* [Ace](view/template_ace_0)
* [Amber](view/template_amber_0)
* [Amber Embedded](view/template_amber_1_embedded)
* [Handlebars](view/template_handlebars_0)
* Third-Parties
* [Render `valyala/quicktemplate` templates](view/quicktemplate)
Expand Down
4 changes: 3 additions & 1 deletion _examples/file-server/embedding-files-into-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
)

// Follow these steps first:
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -prefix "assets" -fs ./assets/...
// $ go run .
// "physical" files are not used, you can delete the "assets" folder and run the example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (

// How to run:
//
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -prefix "../embedding-files-into-app/assets/" -fs ../embedding-files-into-app/assets/...
// $ go run .
// Time to complete the compression and caching of [2/3] files: 31.9998ms
Expand Down
4 changes: 3 additions & 1 deletion _examples/file-server/http2push-embedded/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

// How to run:
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -nomemcopy -fs -prefix "../http2push/assets" ../http2push/assets/...
// # OR if the ./assets directory was inside this example foder:
// # go-bindata -nomemcopy -refix "assets" ./assets/...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import "github.com/kataras/iris/v12"

// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"github.com/kataras/iris/v12"
)

// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go-bindata -nomemcopy -fs ./public/...
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .

var page = struct {
Expand All @@ -14,20 +16,16 @@ var page = struct {

func newApp() *iris.Application {
app := iris.New()
app.RegisterView(iris.HTML("./public", ".html").Binary(Asset, AssetNames))

app.RegisterView(iris.HTML(AssetFile(), ".html"))

app.HandleDir("/", AssetFile())

app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Page", page)
ctx.View("index.html")
})

// We didn't add a `-prefix "public"` argument on go-bindata command
// because the view's `Assset` and `AssetNames` require fullpath.
// Make use of the `PrefixDir` to serve assets on cases like that;
// when bindata.go file contains files that are
// not necessary public assets to be served.
app.HandleDir("/", iris.PrefixDir("public", AssetFile()))

return app
}

Expand Down
Loading

0 comments on commit e1f25eb

Please sign in to comment.