改进ghttp.Server Session示例

This commit is contained in:
John
2018-04-30 22:28:01 +08:00
parent 982bbec818
commit 299db4ebfe
3 changed files with 20 additions and 11 deletions

View File

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

View File

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