mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
5ffc7911cd
Also disable version updater on Iris benchmark source code files. It may runs ever faster than before if you started the benchmarks immediately after the banner 👍
Former-commit-id: a55dc1e0b658d7386229c32ba6953b1ea60f2872
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
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)
|
|
*/
|
|
|
|
// 24 August 2017: Iris has a built'n version updater but we don't need it
|
|
// when benchmarking...
|
|
app.Run(iris.Addr(":5000"), iris.WithoutVersionChecker)
|
|
}
|
|
|
|
// 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")
|
|
}
|