mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
add example for session handling of ghttp
This commit is contained in:
25
.example/net/ghttp/server/session/session_map.go
Normal file
25
.example/net/ghttp/server/session/session_map.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.SetSessionMaxAge(60)
|
||||
s.BindHandler("/set", func(r *ghttp.Request) {
|
||||
r.Session.Set("captcha", map[string]string{
|
||||
"key": "value",
|
||||
})
|
||||
r.Response.Write("ok")
|
||||
})
|
||||
s.BindHandler("/get", func(r *ghttp.Request) {
|
||||
fmt.Println(r.Session.Get("captcha"))
|
||||
r.Response.Write(r.Session.Get("captcha"))
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user