1 Star 2 Fork 0

api-go / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
kataras 提交于 2017-08-24 15:40 . Add a TODO on the latest HISTORY.md entry
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")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netscript/iris.git
git@gitee.com:netscript/iris.git
netscript
iris
iris
v8.5.9

搜索帮助

344bd9b3 5694891 D2dac590 5694891