f5/context.go
aozhiwei 72fe2ec77d 1
2020-12-19 12:00:08 +08:00

72 lines
1.3 KiB
Go

package f5
import (
"net/http"
"q5"
)
type Context struct {
s *HttpServer
w *http.ResponseWriter
r *http.Request
c *middleware
l *q5.ListHead
aborted bool
suspended bool
}
func (this *Context) do() {
this.l.ForEach(
func(data interface{}) bool {
m := data.(*middleware)
this.c = m
m.handlerFunc(this)
return !this.aborted && !this.suspended
})
}
func (this *Context) Next() {
this.suspended = true
this.l.ForEachFrom(this.c.entry.Next(),
func(data interface{}) bool {
m := data.(*middleware)
this.c = m
m.handlerFunc(this)
return !this.aborted
})
}
func (this *Context) Abort() {
this.aborted = true
}
func (this *Context) Request(name string) *q5.XValue {
return q5.Request(this.r, name)
}
func (this *Context) Header(name string) string {
return ""
}
func (this *Context) Response(data string) {
q5.Response(this.w, data)
}
func (this *Context)ResponseErr(errCode int32, errMsg string) {
respObj := q5.NewMxoObject()
respObj.SetXValue("errcode", q5.NewXInt32(errCode))
respObj.SetXValue("errmsg", q5.NewXString(errMsg))
q5.Response(this.w, respObj.ToJsonStr())
}
func (this *Context) ResponseOk() {
q5.ResponseOk(this.w)
}
func (this *Context) Set(key string, val interface{}) {
}
func (this *Context) Get(key string) interface{} {
return nil
}