minor: compatibility: context render

This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-09-27 20:43:01 +03:00
parent 028ad9f11e
commit 29010bfd7c
No known key found for this signature in database
GPG Key ID: 403EEB7885C79503
4 changed files with 23 additions and 1 deletions

View File

@ -28,6 +28,8 @@ The codebase for Dependency Injection, Internationalization and localization and
## Fixes and Improvements ## Fixes and Improvements
- Add `Context.Render` method for compatibility.
- Support of embedded [locale files](https://github.com/kataras/iris/blob/master/_examples/i18n/template-embedded/main.go) using standard `embed.FS` with the new `LoadFS` function. - Support of embedded [locale files](https://github.com/kataras/iris/blob/master/_examples/i18n/template-embedded/main.go) using standard `embed.FS` with the new `LoadFS` function.
- Support of direct embedded view engines (`HTML, Blocks, Django, Handlebars, Pug, Amber, Jet` and `Ace`) with `embed.FS` or `fs.FS` (in addition to `string` and `http.FileSystem` types). - Support of direct embedded view engines (`HTML, Blocks, Django, Handlebars, Pug, Amber, Jet` and `Ace`) with `embed.FS` or `fs.FS` (in addition to `string` and `http.FileSystem` types).
- Add support for `embed.FS` and `fs.FS` on `app.HandleDir`. - Add support for `embed.FS` and `fs.FS` on `app.HandleDir`.

View File

@ -62,7 +62,7 @@ type (
func main() { func main() {
app := iris.New() app := iris.New()
app.Post("/", your_package.Handle(handler)) app.Post("/", x.Handle(handler))
app.Listen(":8080") app.Listen(":8080")
} }

View File

@ -4204,6 +4204,26 @@ func (ctx *Context) handleContextError(err error) {
// keep the error non nil so the caller has control over further actions. // keep the error non nil so the caller has control over further actions.
} }
// Render writes the response headers and calls the given renderer "r" to render data.
// This method can be used while migrating from other frameworks.
func (ctx *Context) Render(statusCode int, r interface {
// Render should push data with custom content type to the client.
Render(http.ResponseWriter) error
// WriteContentType writes custom content type to the response.
WriteContentType(w http.ResponseWriter)
}) {
ctx.StatusCode(statusCode)
if statusCode >= 100 && statusCode <= 199 || statusCode == http.StatusNoContent || statusCode == http.StatusNotModified {
r.WriteContentType(ctx.writer)
return
}
if err := r.Render(ctx.writer); err != nil {
ctx.StopWithError(http.StatusInternalServerError, err)
}
}
// JSON marshals the given "v" value to JSON and writes the response to the client. // JSON marshals the given "v" value to JSON and writes the response to the client.
// Look the Configuration.EnableProtoJSON and EnableEasyJSON too. // Look the Configuration.EnableProtoJSON and EnableEasyJSON too.
// //