mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
fix all _examples to the newest mvc, add comments to those examples and add a package-level .Configure in order to make it easier for new users. Add a deprecated panic if app.Controller is used with a small tutorial and future resource link so they can re-write their mvc app's definitions
Former-commit-id: bf07696041be9e3d178ce3c42ccec2df4bfdb2af
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/kataras/iris/_examples/structuring/login-mvc-single-responsibility-package/user"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/mvc"
|
||||
"github.com/kataras/iris/sessions"
|
||||
)
|
||||
|
||||
@@ -19,13 +20,7 @@ func main() {
|
||||
|
||||
app.StaticWeb("/public", "./public")
|
||||
|
||||
manager := sessions.New(sessions.Config{
|
||||
Cookie: "sessioncookiename",
|
||||
Expires: 24 * time.Hour,
|
||||
})
|
||||
users := user.NewDataSource()
|
||||
|
||||
app.Controller("/user", new(user.Controller), manager, users)
|
||||
mvc.Configure(app, configureMVC)
|
||||
|
||||
// http://localhost:8080/user/register
|
||||
// http://localhost:8080/user/login
|
||||
@@ -35,9 +30,22 @@ func main() {
|
||||
app.Run(iris.Addr(":8080"), configure)
|
||||
}
|
||||
|
||||
func configureMVC(app *mvc.Application) {
|
||||
manager := sessions.New(sessions.Config{
|
||||
Cookie: "sessioncookiename",
|
||||
Expires: 24 * time.Hour,
|
||||
})
|
||||
|
||||
userApp := app.NewChild(app.Router.Party("/user"))
|
||||
userApp.AddDependencies(
|
||||
user.NewDataSource(),
|
||||
mvc.Session(manager),
|
||||
)
|
||||
userApp.Register(new(user.Controller))
|
||||
}
|
||||
|
||||
func configure(app *iris.Application) {
|
||||
app.Configure(
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
iris.WithCharset("UTF-8"),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user