增加表关联新建功能,同时修复数据库bug
This commit is contained in:
+73
-52
@@ -4,9 +4,8 @@ import (
|
||||
"../../hotime"
|
||||
"../../hotime/common"
|
||||
"./admin"
|
||||
"errors"
|
||||
"./app"
|
||||
"fmt"
|
||||
"golang.org/x/net/websocket"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -14,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println(time.Now().Weekday().String())
|
||||
appIns := hotime.Init("config/config.json")
|
||||
//RESTfull接口适配
|
||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
||||
@@ -73,26 +72,47 @@ func main() {
|
||||
//列表检索
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "GET" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
||||
}
|
||||
//新建
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "POST" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
||||
}
|
||||
//查询单条
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
||||
}
|
||||
//更新
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "PUT" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
||||
}
|
||||
//移除
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "DELETE" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
||||
}
|
||||
context.View()
|
||||
@@ -104,54 +124,55 @@ func main() {
|
||||
|
||||
appIns.Run(hotime.Router{
|
||||
"admin": admin.Project,
|
||||
"app": hotime.Proj{
|
||||
"index": hotime.Ctr{
|
||||
"test": func(this *hotime.Context) {
|
||||
|
||||
data := this.Db.Get("cached", "*")
|
||||
fmt.Println(data)
|
||||
fmt.Println(this.Session("test").ToCeilInt())
|
||||
this.Session("test1", 98984984)
|
||||
fmt.Println(this.Session("test1").Data)
|
||||
this.Error.SetError(errors.New("dasdasdas"))
|
||||
//fmt.Println(this.Db.GetTag())
|
||||
//this.Application.Log.Error("dasdasdas")
|
||||
//this.Log.Error("dadasdasd")
|
||||
//x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||
//
|
||||
// db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
||||
//
|
||||
// return true
|
||||
//})
|
||||
//hotime.LogError("dasdasdasdasdas")
|
||||
this.Display(5, "dsadas")
|
||||
},
|
||||
"websocket": func(this *hotime.Context) {
|
||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||
for true {
|
||||
msg := make([]byte, 5120)
|
||||
n, err := ws.Read(msg)
|
||||
go func() {
|
||||
time.Sleep(time.Second * 5)
|
||||
ws.Write([]byte("dsadasdasgregergrerge"))
|
||||
|
||||
}()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Printf("Receive: %s\n", msg[:n])
|
||||
|
||||
send_msg := "[" + string(msg[:n]) + "]"
|
||||
m, err := ws.Write([]byte(send_msg))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Printf("Send: %s\n", msg[:m])
|
||||
}
|
||||
})
|
||||
hdler.ServeHTTP(this.Resp, this.Req)
|
||||
},
|
||||
},
|
||||
},
|
||||
"app": app.Project,
|
||||
//"app": hotime.Proj{
|
||||
// "index": hotime.Ctr{
|
||||
// "test": func(this *hotime.Context) {
|
||||
//
|
||||
// data := this.Db.Get("cached", "*")
|
||||
// fmt.Println(data)
|
||||
// fmt.Println(this.Session("test").ToCeilInt())
|
||||
// this.Session("test1", 98984984)
|
||||
// fmt.Println(this.Session("test1").Data)
|
||||
// this.Error.SetError(errors.New("dasdasdas"))
|
||||
// //fmt.Println(this.Db.GetTag())
|
||||
// //this.Application.Log.Error("dasdasdas")
|
||||
// //this.Log.Error("dadasdasd")
|
||||
// //x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||
// //
|
||||
// // db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
||||
// //
|
||||
// // return true
|
||||
// //})
|
||||
// //hotime.LogError("dasdasdasdasdas")
|
||||
// this.Display(5, "dsadas")
|
||||
// },
|
||||
// "websocket": func(this *hotime.Context) {
|
||||
// hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||
// for true {
|
||||
// msg := make([]byte, 5120)
|
||||
// n, err := ws.Read(msg)
|
||||
// go func() {
|
||||
// time.Sleep(time.Second * 5)
|
||||
// ws.Write([]byte("dsadasdasgregergrerge"))
|
||||
//
|
||||
// }()
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("Receive: %s\n", msg[:n])
|
||||
//
|
||||
// send_msg := "[" + string(msg[:n]) + "]"
|
||||
// m, err := ws.Write([]byte(send_msg))
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("Send: %s\n", msg[:m])
|
||||
// }
|
||||
// })
|
||||
// hdler.ServeHTTP(this.Resp, this.Req)
|
||||
// },
|
||||
// },
|
||||
//},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user