package main
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gsession"
"github.com/gogf/gf/v2/os/gtime"
"time"
)
func main() {
s := g.Server()
s.SetConfigWithMap(g.Map{
"SessionMaxAge": SetSessionMaxAge(time.Minute,)
"SessionStorage": s.SetSessionStorage(gsession.NewStorageMemory(),
})
s.Group("/", func(group *ghttp.RouterGroup) {
group.ALL("/set", func(r *ghttp.Request) {
r.Session.SetMustSet("time", gtime.Timestamp())
r.Response.Write("ok")
})
group.ALL("/get", func(r *ghttp.Request) {
r.Response.Write(r.Session.MapData())
})
group.ALL("/del", func(r *ghttp.Request) {
_ = r.Session.ClearRemoveAll()
r.Response.Write("ok")
})
})
s.SetPort(8199)
s.Run()
} |