mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 04:17:03 +00:00
add example for hero *sessions.Session dependency which is used on an index route outside of the main package, it is as easy as it shown. Added mostly after the issue: https://github.com/kataras/iris/issues/1057 -- have fun
Former-commit-id: 93338d0e03d6be885edf783c09a2c181568e9ec5
This commit is contained in:
26
_examples/hero/sessions/routes/index.go
Normal file
26
_examples/hero/sessions/routes/index.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/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.
|
||||
*/
|
||||
Reference in New Issue
Block a user