1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

Add status code 103 Early Hints. Add the ability to customize and change the order of controller's fields and their registered valid dependencies relative to: #1343

Former-commit-id: 5bd9e02e5fafca135d17cad87f4a9aec526b333b
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-08-26 16:43:02 +03:00
parent 9d09e8637b
commit bd5f96086b
10 changed files with 116 additions and 33 deletions

View File

@@ -39,7 +39,12 @@ var HeroDependencies = true
//
// See `mvc#New` for more.
type Application struct {
Dependencies di.Values
Dependencies di.Values
// Sorter is a `di.Sorter`, can be used to customize the order of controller's fields
// and their available bindable values to set.
// Sorting matters only when a field can accept more than one registered value.
// Defaults to nil; order of registration matters when more than one field can accept the same value.
Sorter di.Sorter
Router router.Party
Controllers []*ControllerActivator
websocketControllers []websocket.ConnHandler
@@ -129,6 +134,15 @@ Set the Logger's Level to "debug" to view the active dependencies per controller
return app
}
// SortByNumMethods is the same as `app.Sorter = di.SortByNumMethods` which
// prioritize fields and their available values (only if more than one)
// with the highest number of methods,
// this way an empty interface{} is getting the "thinnest" available value.
func (app *Application) SortByNumMethods() *Application {
app.Sorter = di.SortByNumMethods
return app
}
// Handle serves a controller for the current mvc application's Router.
// It accept any custom struct which its functions will be transformed
// to routes.
@@ -218,7 +232,7 @@ func (app *Application) GetNamespaces() websocket.Namespaces {
func (app *Application) handle(controller interface{}) *ControllerActivator {
// initialize the controller's activator, nothing too magical so far.
c := newControllerActivator(app.Router, controller, app.Dependencies, app.ErrorHandler)
c := newControllerActivator(app.Router, controller, app.Dependencies, app.Sorter, app.ErrorHandler)
// check the controller's "BeforeActivation" or/and "AfterActivation" method(s) between the `activate`
// call, which is simply parses the controller's methods, end-dev can register custom controller's methods