69 lines
1.0 KiB
Go
69 lines
1.0 KiB
Go
|
package hotime
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Context struct {
|
||
|
LastErr Error
|
||
|
tag int64
|
||
|
Resp http.ResponseWriter
|
||
|
Req *http.Request
|
||
|
App *App
|
||
|
RouterString []string
|
||
|
Config Map
|
||
|
Db *HoTimeDB
|
||
|
resp Map
|
||
|
CacheIns
|
||
|
SessionIns
|
||
|
}
|
||
|
|
||
|
//唯一标志
|
||
|
func (this *Context) GetTag() int64 {
|
||
|
|
||
|
if this.tag == int64(0) {
|
||
|
this.tag = time.Now().UnixNano()
|
||
|
}
|
||
|
return this.tag
|
||
|
}
|
||
|
|
||
|
//唯一标志
|
||
|
func (this *Context) Mtd(router [3]string) Map {
|
||
|
this.App.Router[router[0]][router[1]][router[2]](this)
|
||
|
d := this.resp
|
||
|
this.resp = nil
|
||
|
return d
|
||
|
}
|
||
|
|
||
|
//打印
|
||
|
func (this *Context) Display(statu int, data interface{}) {
|
||
|
|
||
|
resp := Map{"statu": statu}
|
||
|
if statu != 0 {
|
||
|
temp := Map{}
|
||
|
temp["type"] = 0
|
||
|
temp["msg"] = data
|
||
|
resp["result"] = temp
|
||
|
} else {
|
||
|
resp["result"] = data
|
||
|
}
|
||
|
|
||
|
this.resp = resp
|
||
|
|
||
|
//this.Data=d;
|
||
|
}
|
||
|
|
||
|
func (this *Context) View() {
|
||
|
if this.resp == nil {
|
||
|
return
|
||
|
}
|
||
|
d, err := json.Marshal(this.resp)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
this.resp = nil
|
||
|
this.Resp.Write(d)
|
||
|
}
|