2017-08-04 08:20:59 +00:00
|
|
|
package hotime
|
|
|
|
|
|
|
|
import (
|
2021-05-23 23:27:41 +00:00
|
|
|
. "./cache"
|
|
|
|
. "./common"
|
|
|
|
. "./db"
|
2017-08-04 08:20:59 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Context struct {
|
2021-05-24 21:08:17 +00:00
|
|
|
*Application
|
2017-08-04 08:20:59 +00:00
|
|
|
Resp http.ResponseWriter
|
|
|
|
Req *http.Request
|
|
|
|
RouterString []string
|
|
|
|
Config Map
|
|
|
|
Db *HoTimeDB
|
2020-02-20 06:20:56 +00:00
|
|
|
RespData Map
|
2017-08-04 08:20:59 +00:00
|
|
|
CacheIns
|
|
|
|
SessionIns
|
2017-08-22 08:24:55 +00:00
|
|
|
HandlerStr string //复写请求url
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
// Mtd 唯一标志
|
|
|
|
func (that *Context) Mtd(router [3]string) Map {
|
|
|
|
that.Application.Router[router[0]][router[1]][router[2]](that)
|
|
|
|
d := that.RespData
|
|
|
|
that.RespData = nil
|
2017-08-04 08:20:59 +00:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
//打印
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that *Context) Display(statu int, data interface{}) {
|
2017-08-04 08:20:59 +00:00
|
|
|
|
|
|
|
resp := Map{"statu": statu}
|
|
|
|
if statu != 0 {
|
|
|
|
temp := Map{}
|
2017-08-10 10:14:56 +00:00
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
tpe := that.Config.GetMap("error").GetString(ObjToStr(statu))
|
2017-08-22 08:24:55 +00:00
|
|
|
if tpe == "" {
|
2021-05-23 23:27:41 +00:00
|
|
|
//logFmt(errors.New("找不到对应的错误码"), 2, LOG_WARN)
|
2017-08-10 10:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
temp["type"] = tpe
|
2017-08-04 08:20:59 +00:00
|
|
|
temp["msg"] = data
|
|
|
|
resp["result"] = temp
|
2021-06-03 18:57:56 +00:00
|
|
|
//兼容android等需要json转对象的服务
|
|
|
|
resp["error"] = temp
|
2017-08-04 08:20:59 +00:00
|
|
|
} else {
|
|
|
|
resp["result"] = data
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
that.RespData = resp
|
2017-08-04 08:20:59 +00:00
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
//that.Data=d;
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that *Context) View() {
|
|
|
|
if that.RespData == nil {
|
2017-08-04 08:20:59 +00:00
|
|
|
return
|
|
|
|
}
|
2021-05-24 21:08:17 +00:00
|
|
|
d, err := json.Marshal(that.RespData)
|
2017-08-04 08:20:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-05-24 21:08:17 +00:00
|
|
|
that.RespData = nil
|
|
|
|
that.Resp.Write(d)
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|