67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package hotime
|
|
|
|
import (
|
|
. "./cache"
|
|
. "./common"
|
|
. "./db"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type Context struct {
|
|
*Application
|
|
Resp http.ResponseWriter
|
|
Req *http.Request
|
|
RouterString []string
|
|
Config Map
|
|
Db *HoTimeDB
|
|
RespData Map
|
|
CacheIns
|
|
SessionIns
|
|
HandlerStr string //复写请求url
|
|
}
|
|
|
|
// 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
|
|
return d
|
|
}
|
|
|
|
//打印
|
|
func (that *Context) Display(statu int, data interface{}) {
|
|
|
|
resp := Map{"statu": statu}
|
|
if statu != 0 {
|
|
temp := Map{}
|
|
|
|
tpe := that.Config.GetMap("error").GetString(ObjToStr(statu))
|
|
if tpe == "" {
|
|
//logFmt(errors.New("找不到对应的错误码"), 2, LOG_WARN)
|
|
}
|
|
|
|
temp["type"] = tpe
|
|
temp["msg"] = data
|
|
resp["result"] = temp
|
|
} else {
|
|
resp["result"] = data
|
|
}
|
|
|
|
that.RespData = resp
|
|
|
|
//that.Data=d;
|
|
}
|
|
|
|
func (that *Context) View() {
|
|
if that.RespData == nil {
|
|
return
|
|
}
|
|
d, err := json.Marshal(that.RespData)
|
|
if err != nil {
|
|
return
|
|
}
|
|
that.RespData = nil
|
|
that.Resp.Write(d)
|
|
}
|