mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
改进ghttp传递给注册函数的参数,简化使用
This commit is contained in:
@ -11,9 +11,9 @@ func init() {
|
||||
}
|
||||
|
||||
// 用于函数映射
|
||||
func Cookie(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
func Cookie(r *ghttp.Request) {
|
||||
datetime := r.Cookie.Get("datetime")
|
||||
r.Cookie.Set("datetime", gtime.Datetime())
|
||||
|
||||
w.WriteString("datetime:" + datetime)
|
||||
r.Response.WriteString("datetime:" + datetime)
|
||||
}
|
||||
@ -15,7 +15,7 @@ func init() {
|
||||
}
|
||||
|
||||
// 用于对象映射
|
||||
func (d *ControllerDomain) Show(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("It's show time bibi!")
|
||||
func (d *ControllerDomain) Show(r *ghttp.Request) {
|
||||
r.Response.WriteString("It's show time bibi!")
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,6 @@ func init() {
|
||||
}
|
||||
|
||||
// 用于函数映射
|
||||
func Hello(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("Hello World!")
|
||||
func Hello(r *ghttp.Request) {
|
||||
r.Response.WriteString("Hello World!")
|
||||
}
|
||||
@ -8,7 +8,7 @@ func init() {
|
||||
ghttp.GetServer().BindObject("/object", &Object{})
|
||||
}
|
||||
|
||||
func (o *Object) Show(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("It's show time bibi!")
|
||||
func (o *Object) Show(r *ghttp.Request) {
|
||||
r.Response.WriteString("It's show time bibi!")
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ func init() {
|
||||
ghttp.GetServer().BindObjectRest("/object-rest", &ObjectRest{})
|
||||
}
|
||||
|
||||
func (o *ObjectRest) Get(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("It's show time bibi!")
|
||||
func (o *ObjectRest) Get(r *ghttp.Request) {
|
||||
r.Response.WriteString("It's show time bibi!")
|
||||
}
|
||||
|
||||
|
||||
@ -11,9 +11,9 @@ func init() {
|
||||
}
|
||||
|
||||
// 用于函数映射
|
||||
func Session(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
func Session(r *ghttp.Request) {
|
||||
id := r.Session.GetInt("id")
|
||||
r.Session.Set("id", id + 1)
|
||||
|
||||
w.WriteString("id:" + strconv.Itoa(id))
|
||||
r.Response.WriteString("id:" + strconv.Itoa(id))
|
||||
}
|
||||
Reference in New Issue
Block a user