1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 20:41:57 +00:00

.NET Core (no mvc) with Sessions vs Iris (no mvc) with Sessions

Former-commit-id: 04a9660645a824dfbc49414605aeff2b3ff88b55
This commit is contained in:
kataras
2017-08-21 13:29:49 +03:00
parent 14aa770869
commit 0c403fd0c6
8 changed files with 264 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
package main
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/sessions"
)
var sess = sessions.New(sessions.Config{
Cookie: ".cookiesession.id",
Expires: time.Minute,
})
func main() {
app := iris.New()
app.Get("/setget", h)
/*
Test them one by one by these methods:
app.Get("/get", getHandler)
app.Post("/set", postHandler)
app.Delete("/del", delHandler)
*/
app.Run(iris.Addr(":5000"))
}
// Set and Get
func h(ctx context.Context) {
session := sess.Start(ctx)
session.Set("key", "value")
value := session.GetString("key")
if value == "" {
ctx.WriteString("NOT_OK")
return
}
ctx.WriteString(value)
}
// Get
func getHandler(ctx context.Context) {
session := sess.Start(ctx)
value := session.GetString("key")
if value == "" {
ctx.WriteString("NOT_OK")
return
}
ctx.WriteString(value)
}
// Set
func postHandler(ctx context.Context) {
session := sess.Start(ctx)
session.Set("key", "value")
ctx.WriteString("OK")
}
// Delete
func delHandler(ctx context.Context) {
session := sess.Start(ctx)
session.Delete("key")
ctx.WriteString("OK")
}