mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 07:20:35 +01:00
minor: compatibility: context render
This commit is contained in:
parent
028ad9f11e
commit
29010bfd7c
|
@ -28,6 +28,8 @@ The codebase for Dependency Injection, Internationalization and localization and
|
|||
|
||||
## 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 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`.
|
||||
|
|
|
@ -62,7 +62,7 @@ type (
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Post("/", your_package.Handle(handler))
|
||||
app.Post("/", x.Handle(handler))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
|
|
|
@ -4204,6 +4204,26 @@ func (ctx *Context) handleContextError(err error) {
|
|||
// 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.
|
||||
// Look the Configuration.EnableProtoJSON and EnableEasyJSON too.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue
Block a user