改进ghttp传递给注册函数的参数,简化使用

This commit is contained in:
John
2018-01-02 15:52:32 +08:00
parent 762e2c8dea
commit d4f992bfc4
18 changed files with 167 additions and 123 deletions

View File

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

View File

@ -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!")
}

View File

@ -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!")
}

View File

@ -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!")
}

View File

@ -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!")
}

View File

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