1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 10:57:05 +00:00

New: gRPC MVC features, new WithLowercaseRouting option and add some new context methods

read HISTORY.md


Former-commit-id: 30a16cceb11f754aa32923058abeda1e736350e7
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-25 02:30:19 +03:00
parent 0cf5d5a4a3
commit 5d3c96947c
21 changed files with 566 additions and 185 deletions

View File

@@ -111,6 +111,15 @@ func (app *Application) Register(dependencies ...interface{}) *Application {
return app
}
// Option is an interface which does contain a single `Apply` method that accepts
// a `ControllerActivator`. It can be passed on `Application.Handle` method to
// mdoify the behavior right after the `BeforeActivation` state.
//
// See `GRPC` package-level structure too.
type Option interface {
Apply(*ControllerActivator)
}
// Handle serves a controller for the current mvc application's Router.
// It accept any custom struct which its functions will be transformed
// to routes.
@@ -154,9 +163,12 @@ func (app *Application) Register(dependencies ...interface{}) *Application {
// Result or (Result, error)
// where Get is an HTTP Method func.
//
// Default behavior can be changed through second, variadic, variable "options",
// e.g. Handle(controller, GRPC {Server: grpcServer, Strict: true})
//
// Examples at: https://github.com/kataras/iris/tree/master/_examples/mvc
func (app *Application) Handle(controller interface{}) *Application {
app.handle(controller)
func (app *Application) Handle(controller interface{}, options ...Option) *Application {
app.handle(controller, options...)
return app
}
@@ -195,7 +207,7 @@ func (app *Application) GetNamespaces() websocket.Namespaces {
return websocket.JoinConnHandlers(app.websocketControllers...).GetNamespaces()
}
func (app *Application) handle(controller interface{}) *ControllerActivator {
func (app *Application) handle(controller interface{}, options ...Option) *ControllerActivator {
// initialize the controller's activator, nothing too magical so far.
c := newControllerActivator(app, controller)
@@ -208,6 +220,12 @@ func (app *Application) handle(controller interface{}) *ControllerActivator {
before.BeforeActivation(c)
}
for _, opt := range options {
if opt != nil {
opt.Apply(c)
}
}
c.activate()
if after, okAfter := controller.(interface {