2017-08-17 02:37:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-21 20:52:03 +00:00
|
|
|
"../../hotime"
|
2021-05-28 18:57:03 +00:00
|
|
|
"./admin"
|
2021-05-28 16:15:13 +00:00
|
|
|
"errors"
|
2017-09-05 03:09:13 +00:00
|
|
|
"fmt"
|
|
|
|
"golang.org/x/net/websocket"
|
2018-04-08 16:02:13 +00:00
|
|
|
"time"
|
2017-08-17 02:37:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-04-04 18:44:00 +00:00
|
|
|
|
2021-06-04 02:04:37 +00:00
|
|
|
appIns := hotime.Init("config/config.json")
|
2021-05-28 18:57:03 +00:00
|
|
|
//RESTfull接口适配
|
2017-09-05 03:09:13 +00:00
|
|
|
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
2021-05-28 18:57:03 +00:00
|
|
|
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
|
|
|
!(context.Router[context.RouterString[0]] != nil &&
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
//排除无效操作
|
|
|
|
if len(context.RouterString) == 2 &&
|
|
|
|
context.Req.Method != "GET" &&
|
|
|
|
context.Req.Method != "POST" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
//列表检索
|
|
|
|
if len(context.RouterString) == 2 &&
|
|
|
|
context.Req.Method == "GET" {
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
|
|
|
}
|
|
|
|
//新建
|
|
|
|
if len(context.RouterString) == 2 &&
|
|
|
|
context.Req.Method == "POST" {
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
|
|
|
}
|
|
|
|
//查询单条
|
|
|
|
if len(context.RouterString) == 3 &&
|
|
|
|
context.Req.Method == "GET" {
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
|
|
|
}
|
|
|
|
//更新
|
|
|
|
if len(context.RouterString) == 3 &&
|
|
|
|
context.Req.Method == "PUT" {
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
|
|
|
}
|
|
|
|
//移除
|
|
|
|
if len(context.RouterString) == 3 &&
|
|
|
|
context.Req.Method == "DELETE" {
|
|
|
|
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
|
|
|
}
|
|
|
|
context.View()
|
|
|
|
return false
|
2017-09-05 03:09:13 +00:00
|
|
|
})
|
2017-08-17 02:37:00 +00:00
|
|
|
|
2021-06-03 18:57:56 +00:00
|
|
|
//makeCode := code.MakeCode{}
|
|
|
|
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
|
|
|
|
|
2017-09-05 03:09:13 +00:00
|
|
|
appIns.Run(hotime.Router{
|
2021-06-02 21:31:09 +00:00
|
|
|
"admin": admin.Project,
|
2017-09-05 03:09:13 +00:00
|
|
|
"app": hotime.Proj{
|
|
|
|
"index": hotime.Ctr{
|
|
|
|
"test": func(this *hotime.Context) {
|
2021-05-28 15:48:33 +00:00
|
|
|
data := this.Db.Get("cached", "*")
|
|
|
|
fmt.Println(data)
|
|
|
|
fmt.Println(this.Session("test").ToCeilInt())
|
|
|
|
this.Session("test1", 98984984)
|
|
|
|
fmt.Println(this.Session("test1").Data)
|
2021-05-28 16:15:13 +00:00
|
|
|
this.Error.SetError(errors.New("dasdasdas"))
|
2021-05-24 21:28:56 +00:00
|
|
|
//fmt.Println(this.Db.GetTag())
|
|
|
|
//this.Application.Log.Error("dasdasdas")
|
|
|
|
//this.Log.Error("dadasdasd")
|
2017-10-27 04:28:47 +00:00
|
|
|
//x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
|
|
|
//
|
|
|
|
// db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
|
|
|
//
|
|
|
|
// return true
|
|
|
|
//})
|
2021-05-23 23:27:41 +00:00
|
|
|
//hotime.LogError("dasdasdasdasdas")
|
2017-10-27 04:28:47 +00:00
|
|
|
this.Display(5, "dsadas")
|
2017-09-05 03:09:13 +00:00
|
|
|
},
|
|
|
|
"websocket": func(this *hotime.Context) {
|
|
|
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
|
|
|
for true {
|
|
|
|
msg := make([]byte, 5120)
|
|
|
|
n, err := ws.Read(msg)
|
2018-04-08 16:02:13 +00:00
|
|
|
go func() {
|
2019-11-10 08:42:49 +00:00
|
|
|
time.Sleep(time.Second * 5)
|
2018-04-08 16:02:13 +00:00
|
|
|
ws.Write([]byte("dsadasdasgregergrerge"))
|
2017-09-05 03:09:13 +00:00
|
|
|
|
2018-04-08 16:02:13 +00:00
|
|
|
}()
|
2017-09-05 03:09:13 +00:00
|
|
|
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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-08-17 02:37:00 +00:00
|
|
|
}
|