iris/_examples/hero/sessions/routes/index.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

27 lines
890 B
Go

package routes
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
)
// Index will increment a simple int version based on the visits that this user/session did.
func Index(ctx iris.Context, session *sessions.Session) {
// it increments a "visits" value of integer by one,
// if the entry with key 'visits' doesn't exist it will create it for you.
visits := session.Increment("visits", 1)
// write the current, updated visits.
ctx.Writef("%d visit(s) from my current session", visits)
}
/*
You can also do anything that an MVC function can, i.e:
func Index(ctx iris.Context,session *sessions.Session) string {
visits := session.Increment("visits", 1)
return fmt.Spritnf("%d visit(s) from my current session", visits)
}
// you can also omit iris.Context input parameter and use dependency injection for LoginForm and etc. <- look the mvc examples.
*/