mirror of
https://github.com/kataras/iris.git
synced 2025-12-23 12:57:05 +00:00
Replace controller's .Register with .Handle and AddDependencies with .Register in order to be aligned with the 'hero' package, all examples and docs are updated, it's crazy how I can't stop even on Christmas
Former-commit-id: 3b42963e9806e327ee42942cf156bda6059eaf8f
This commit is contained in:
@@ -14,7 +14,7 @@ All HTTP Methods are supported, for example if want to serve `GET`
|
||||
then the controller should have a function named `Get()`,
|
||||
you can define more than one method function to serve in the same Controller.
|
||||
|
||||
Register custom controller's struct's methods as handlers with custom paths(even with regex parametermized path)
|
||||
Serve custom controller's struct's methods as handlers with custom paths(even with regex parametermized path)
|
||||
via the `BeforeActivation` custom event callback, per-controller. Example:
|
||||
|
||||
```go
|
||||
@@ -30,9 +30,9 @@ func main() {
|
||||
}
|
||||
|
||||
func myMVC(app *mvc.Application) {
|
||||
// app.AddDependencies(...)
|
||||
// app.Register(...)
|
||||
// app.Router.Use/UseGlobal/Done(...)
|
||||
app.Register(new(MyController))
|
||||
app.Handle(new(MyController))
|
||||
}
|
||||
|
||||
type MyController struct {}
|
||||
@@ -79,13 +79,13 @@ Optional `EndRequest(ctx)` function to perform any finalization after any method
|
||||
Inheritance, recursively, see for example our `mvc.SessionController`, it has the `Session *sessions.Session` and `Manager *sessions.Sessions` as embedded fields
|
||||
which are filled by its `BeginRequest`, [here](https://github.com/kataras/iris/blob/master/mvc/session_controller.go).
|
||||
This is just an example, you could use the `sessions.Session` as a dependency to the MVC Application, i.e
|
||||
`mvcApp.AddDependencies(sessions.New(sessions.Config{Cookie: "iris_session_id"}).Start)`.
|
||||
`mvcApp.Register(sessions.New(sessions.Config{Cookie: "iris_session_id"}).Start)`.
|
||||
|
||||
Access to the dynamic path parameters via the controller's methods' input arguments, no binding is needed.
|
||||
When you use the Iris' default syntax to parse handlers from a controller, you need to suffix the methods
|
||||
with the `By` word, uppercase is a new sub path. Example:
|
||||
|
||||
If `mvc.New(app.Party("/user")).Register(new(user.Controller))`
|
||||
If `mvc.New(app.Party("/user")).Handle(new(user.Controller))`
|
||||
|
||||
- `func(*Controller) Get()` - `GET:/user`.
|
||||
- `func(*Controller) Post()` - `POST:/user`.
|
||||
@@ -96,11 +96,11 @@ If `mvc.New(app.Party("/user")).Register(new(user.Controller))`
|
||||
- `func(*Controller) GetBy(id int64)` - `GET:/user/{param:long}`
|
||||
- `func(*Controller) PostBy(id int64)` - `POST:/user/{param:long}`
|
||||
|
||||
If `mvc.New(app.Party("/profile")).Register(new(profile.Controller))`
|
||||
If `mvc.New(app.Party("/profile")).Handle(new(profile.Controller))`
|
||||
|
||||
- `func(*Controller) GetBy(username string)` - `GET:/profile/{param:string}`
|
||||
|
||||
If `mvc.New(app.Party("/assets")).Register(new(file.Controller))`
|
||||
If `mvc.New(app.Party("/assets")).Handle(new(file.Controller))`
|
||||
|
||||
- `func(*Controller) GetByWildard(path string)` - `GET:/assets/{param:path}`
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ func newApp() *iris.Application {
|
||||
app.Use(recover.New())
|
||||
app.Use(logger.New())
|
||||
|
||||
// Register a controller based on the root Router, "/".
|
||||
mvc.New(app).Register(new(ExampleController))
|
||||
// Serve a controller based on the root Router, "/".
|
||||
mvc.New(app).Handle(new(ExampleController))
|
||||
return app
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func main() {
|
||||
ctx.View("shared/error.html")
|
||||
})
|
||||
|
||||
// ---- Register our controllers. ----
|
||||
// ---- Serve our controllers. ----
|
||||
|
||||
// Prepare our repositories and services.
|
||||
db, err := datasource.LoadUsers(datasource.Memory)
|
||||
@@ -53,8 +53,8 @@ func main() {
|
||||
// for the /users based requests.
|
||||
users.Router.Use(middleware.BasicAuth)
|
||||
// Bind the "userService" to the UserController's Service (interface) field.
|
||||
users.AddDependencies(userService)
|
||||
users.Register(new(controllers.UsersController))
|
||||
users.Register(userService)
|
||||
users.Handle(new(controllers.UsersController))
|
||||
|
||||
// "/user" based mvc application.
|
||||
sessManager := sessions.New(sessions.Config{
|
||||
@@ -62,11 +62,11 @@ func main() {
|
||||
Expires: 24 * time.Hour,
|
||||
})
|
||||
user := mvc.New(app.Party("/user"))
|
||||
user.AddDependencies(
|
||||
user.Register(
|
||||
userService,
|
||||
sessManager.Start,
|
||||
)
|
||||
user.Register(new(controllers.UserController))
|
||||
user.Handle(new(controllers.UserController))
|
||||
|
||||
// http://localhost:8080/noexist
|
||||
// and all controller's methods like
|
||||
|
||||
@@ -20,11 +20,11 @@ func main() {
|
||||
// Load the template files.
|
||||
app.RegisterView(iris.HTML("./web/views", ".html"))
|
||||
|
||||
// Register our controllers.
|
||||
mvc.New(app.Party("/hello")).Register(new(controllers.HelloController))
|
||||
// Serve our controllers.
|
||||
mvc.New(app.Party("/hello")).Handle(new(controllers.HelloController))
|
||||
// You can also split the code you write to configure an mvc.Application
|
||||
// using the `Configure` method, as shown below.
|
||||
mvc.New(app.Party("/movies")).Configure(movies)
|
||||
// using the `mvc.Configure` method, as shown below.
|
||||
mvc.Configure(app.Party("/movies"), movies)
|
||||
|
||||
// http://localhost:8080/hello
|
||||
// http://localhost:8080/hello/iris
|
||||
@@ -52,10 +52,11 @@ func movies(app *mvc.Application) {
|
||||
repo := repositories.NewMovieRepository(datasource.Movies)
|
||||
// Create our movie service, we will bind it to the movie app's dependencies.
|
||||
movieService := services.NewMovieService(repo)
|
||||
app.AddDependencies(movieService)
|
||||
app.Register(movieService)
|
||||
|
||||
// Register our movies controller.
|
||||
// Note that you can register more than one controller
|
||||
// you can alos create child mvc apps using the `movies.NewChild()` if you want.
|
||||
app.Register(new(controllers.MovieController))
|
||||
// serve our movies controller.
|
||||
// Note that you can serve more than one controller
|
||||
// you can also create child mvc apps using the `movies.Party(relativePath)` or `movies.Clone(app.Party(...))`
|
||||
// if you want.
|
||||
app.Handle(new(controllers.MovieController))
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func newApp() *iris.Application {
|
||||
visitApp := mvc.New(app.Party("/"))
|
||||
// bind the current *session.Session, which is required, to the `VisitController.Session`
|
||||
// and the time.Now() to the `VisitController.StartTime`.
|
||||
visitApp.AddDependencies(
|
||||
visitApp.Register(
|
||||
// if dependency is a function which accepts
|
||||
// a Context and returns a single value
|
||||
// then the result type of this function is resolved by the controller
|
||||
@@ -55,7 +55,7 @@ func newApp() *iris.Application {
|
||||
sess.Start,
|
||||
time.Now(),
|
||||
)
|
||||
visitApp.Register(new(VisitController))
|
||||
visitApp.Handle(new(VisitController))
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
mvc.New(app.Party("/")).Register(&globalVisitorsController{visits: 0})
|
||||
mvc.New(app.Party("/")).Handle(&globalVisitorsController{visits: 0})
|
||||
|
||||
// http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"))
|
||||
|
||||
@@ -31,9 +31,9 @@ func configureMVC(m *mvc.Application) {
|
||||
m.Router.Any("/iris-ws.js", websocket.ClientHandler())
|
||||
|
||||
// This will bind the result of ws.Upgrade which is a websocket.Connection
|
||||
// to the controller(s) registered via `m.Register`.
|
||||
m.AddDependencies(ws.Upgrade)
|
||||
m.Register(new(websocketController))
|
||||
// to the controller(s) served by the `m.Handle`.
|
||||
m.Register(ws.Upgrade)
|
||||
m.Handle(new(websocketController))
|
||||
}
|
||||
|
||||
var visits uint64
|
||||
|
||||
Reference in New Issue
Block a user