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

Add session.Destroy (before I've added: Increment & Decrement entry helpers as well) | Improve the debug messages for the controllers

Former-commit-id: f5f17b05252a5032ace1e2d0fdd2304fc4004635
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-16 23:09:00 +02:00
parent b8cafce6b9
commit 68cc6641d4
7 changed files with 119 additions and 53 deletions

View File

@@ -5,12 +5,14 @@ package main
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/_examples/mvc/login/datasource"
"github.com/kataras/iris/_examples/mvc/login/repositories"
"github.com/kataras/iris/_examples/mvc/login/services"
"github.com/kataras/iris/_examples/mvc/login/web/controllers"
"github.com/kataras/iris/_examples/mvc/login/web/middleware"
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
"github.com/kataras/iris/sessions"
)
@@ -34,7 +36,9 @@ func main() {
ctx.View("shared/error.html")
})
// Create our repositories and services.
// ---- Register our controllers. ----
// Prepare our repositories and services.
db, err := datasource.LoadUsers(datasource.Memory)
if err != nil {
app.Logger().Fatalf("error while loading the users: %v", err)
@@ -43,29 +47,38 @@ func main() {
repo := repositories.NewUserRepository(db)
userService := services.NewUserService(repo)
// Register our controllers.
app.Controller("/users", new(controllers.UsersController),
// Add the basic authentication(admin:password) middleware
// for the /users based requests.
middleware.BasicAuth,
// Bind the "userService" to the UserController's Service (interface) field.
userService,
)
// "/users" based mvc application.
users := mvc.New(app.Party("/users"))
// Add the basic authentication(admin:password) middleware
// 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))
// "/user" based mvc application.
sessManager := sessions.New(sessions.Config{
Cookie: "sessioncookiename",
Expires: 24 * time.Hour,
})
app.Controller("/user", new(controllers.UserController), userService, sessManager)
user := mvc.New(app.Party("/user"))
user.AddDependencies(
userService,
mvc.Session(sessManager),
)
user.Register(new(controllers.UserController))
// Start the web server at localhost:8080
// http://localhost:8080/hello
// http://localhost:8080/hello/iris
// http://localhost:8080/noexist
// and all controller's methods like
// http://localhost:8080/users/1
app.Run(
// Starts the web server at localhost:8080
iris.Addr("localhost:8080"),
// Disables the updater.
iris.WithoutVersionChecker,
// Ignores err server closed log when CTRL/CMD+C pressed.
iris.WithoutServerError(iris.ErrServerClosed),
iris.WithOptimizations, // enables faster json serialization and more
// Enables faster json serialization and more.
iris.WithOptimizations,
)
}