add example for session handling of ghttp

This commit is contained in:
John
2019-09-04 20:12:29 +08:00
parent 425d45e502
commit 31e7037e3e

View 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()
}