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

8.4.0 | New MVC Features | Refactor examples and godoc for go 1.9 use. Read HISTORY.md.

Former-commit-id: 90c05e743052bc3722e7fefaa0cbb0ed5153a1fb
This commit is contained in:
kataras
2017-08-27 20:35:23 +03:00
parent a2de506f80
commit 42b123975c
100 changed files with 405 additions and 981 deletions

View File

@@ -4,7 +4,6 @@ import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/sessions"
"github.com/kataras/iris/sessions/sessiondb/redis"
@@ -40,10 +39,10 @@ func main() {
// the rest of the code stays the same.
app := iris.New()
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead")
})
app.Get("/set", func(ctx context.Context) {
app.Get("/set", func(ctx iris.Context) {
s := sess.Start(ctx)
//set session values
s.Set("name", "iris")
@@ -52,29 +51,29 @@ func main() {
ctx.Writef("All ok session setted to: %s", s.GetString("name"))
})
app.Get("/get", func(ctx context.Context) {
app.Get("/get", func(ctx iris.Context) {
// get a specific key, as string, if no found returns just an empty string
name := sess.Start(ctx).GetString("name")
ctx.Writef("The name on the /set was: %s", name)
})
app.Get("/delete", func(ctx context.Context) {
app.Get("/delete", func(ctx iris.Context) {
// delete a specific key
sess.Start(ctx).Delete("name")
})
app.Get("/clear", func(ctx context.Context) {
app.Get("/clear", func(ctx iris.Context) {
// removes all entries
sess.Start(ctx).Clear()
})
app.Get("/destroy", func(ctx context.Context) {
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
sess.Destroy(ctx)
})
app.Get("/update", func(ctx context.Context) {
app.Get("/update", func(ctx iris.Context) {
// updates expire date with a new date
sess.ShiftExpiration(ctx)
})