mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
改进ghttp.Server Session示例
This commit is contained in:
@ -60,7 +60,7 @@ func (r *Response) Write(content ... interface{}) {
|
||||
}
|
||||
r.mu.Lock()
|
||||
for _, v := range content {
|
||||
r.buffer = append(r.buffer, gconv.Bytes(v)...)
|
||||
r.buffer = append(r.buffer, gconv.String(v)...)
|
||||
}
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
18
geg/net/ghttp/session.go
Normal file
18
geg/net/ghttp/session.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.BindHandler("/session", func(r *ghttp.Request) {
|
||||
id := r.Session.GetInt("id")
|
||||
r.Session.Set("id", id + 1)
|
||||
r.Response.Write("id:", id)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
@ -1,15 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.BindHandler("/", func(r *ghttp.Request){
|
||||
r.Response.Write("123")
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user