mirror of
https://github.com/kataras/iris.git
synced 2026-03-03 15:06:03 +00:00
❤️ awesome and unique features for end-developers are coming...
total refactor of the hero and mvc packages, see README#Next (it's not completed yet) Former-commit-id: b85ae99cbfe5965ba919c1e15cf4989e787982c0
This commit is contained in:
63
HISTORY.md
63
HISTORY.md
@@ -21,6 +21,69 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
|
||||
|
||||
**How to upgrade**: Open your command-line and execute this command: `go get github.com/kataras/iris/v12@latest`.
|
||||
|
||||
# Next
|
||||
|
||||
This release introduces new features and some breaking changes inside the `mvc` and `hero` packages.
|
||||
The codebase for dependency injection has been simplified a lot (fewer LOCs and easier to read and follow up).
|
||||
|
||||
Before this release the `iris.Context` was the only one dependency has been automatically binded to the controller's fields or handler's inputs, now the standard `"context"` package's `Context` is also automatically binded and all structs that are not mapping to a registered dependency are now automatically resolved to `payload` XML, YAML, Query, Form and JSON dependencies based on the request's `Content-Type` header (defaults to JSON if client didn't specified a content-type).
|
||||
|
||||
The new release contains a fresh new and awesome feature....**a function dependency can accept previous registered dependencies and update or return a new value of any type**.
|
||||
|
||||
The new implementation is **faster** on both design and serve-time.
|
||||
|
||||
The most common scenario from a route to handle is to:
|
||||
- accept one or more path parameters and request data, a payload
|
||||
- send back a response, a payload (JSON, XML,...)
|
||||
|
||||
The new Iris Dependency Injection feature is about **[33.2% faster](_benchmarks/_internal/README.md#dependency-injection)** than its predecessor on the above case. This drops down even more the performance cost between native handlers and dynamic handlers with dependencies. This reason itself brings us, with safety and performance-wise, to the new `Party.HandleFunc(method, relativePath string, handlersFn ...interface{}) *Route` and `Party.RegisterDependency` method.
|
||||
|
||||
Look how clean your codebase can be when using Iris':
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
type (
|
||||
testInput struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
testOutput struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
func handler(id int, in testInput) testOutput {
|
||||
return testOutput{
|
||||
ID: id,
|
||||
Name: in.Email,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.HandleFunc(iris.MethodPost, "/{id:int}", handler)
|
||||
app.Listen(":5000", iris.WithOptimizations)
|
||||
}
|
||||
```
|
||||
|
||||
Your eyes don't lie you. You read well, no `ctx.ReadJSON(&v)` and `ctx.JSON(send)` neither `error` handling are presented. It is a huge relief but don't worry you can still control everything if you ever need, even errors from dependencies. Any error may occur from request-scoped dependencies or your own handler is dispatched through `Party.GetContainer().GetErrorHandler` which defaults to the `hero.DefaultErrorHandler` which sends a `400 Bad Request` response with the error's text as its body contents. If you want to handle `testInput` otherwise then just add a `Party.RegisterDependency(func(ctx iris.Context) testInput {...})` and you are ready to go.
|
||||
|
||||
New Context Methods:
|
||||
|
||||
- `context.Defer(Handler)` works like `Party.Done` but for the request life-cycle.
|
||||
- `context.ReflectValue() []reflect.Value` stores and returns the `[]reflect.ValueOf(context)`
|
||||
- `context.Controller() reflect.Value` returns the current MVC Controller value (when fired from inside a controller's method).
|
||||
|
||||
Breaking Changes:
|
||||
|
||||
- `var mvc.AutoBinding` removed as the default behavior now resolves such dependencies automatically (see [[FEATURE REQUEST] MVC serving gRPC-compatible controller](https://github.com/kataras/iris/issues/1449))
|
||||
- `mvc#Application.SortByNumMethods()` removed as the default behavior now binds the "thinnest" empty `interface{}` automatically (see [MVC: service injecting fails](https://github.com/kataras/iris/issues/1343))
|
||||
- `mvc#BeforeActivation.Dependencies().Add` should be replaced with `mvc#BeforeActivation.Dependencies().Register` instead.
|
||||
|
||||
# Su, 16 February 2020 | v12.1.8
|
||||
|
||||
New Features:
|
||||
|
||||
Reference in New Issue
Block a user