2022-07-11 03:07:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
|
|
. "code.hoteas.com/golang/hotime/common"
|
|
|
|
"fmt"
|
2022-07-11 11:13:20 +00:00
|
|
|
"golang.org/x/net/websocket"
|
2022-07-11 03:07:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
appIns := Init("config/config.json")
|
|
|
|
appIns.Run(Router{"app": Proj{
|
|
|
|
"user": Ctr{
|
|
|
|
"test": func(that *Context) {
|
|
|
|
fmt.Println("dasdasd")
|
2022-07-11 11:13:20 +00:00
|
|
|
//id := that.Db.Insert("user", Map{"name": "test"})
|
|
|
|
//ok := that.Db.Update("user", Map{"name": "test1"}, Map{"name": "test"})
|
2022-07-11 03:07:17 +00:00
|
|
|
ps := that.Db.Select("user", "*")
|
|
|
|
p := that.Db.Get("user", "*")
|
2022-07-11 11:13:20 +00:00
|
|
|
//row := that.Db.Delete("user", Map{"id": id})
|
|
|
|
//that.Display(0, Slice{id, ok, ps, p, row})
|
|
|
|
that.Display(0, Slice{ps, p})
|
2022-07-11 03:07:17 +00:00
|
|
|
},
|
2022-07-11 11:13:20 +00:00
|
|
|
"websocket": func(that *Context) {
|
|
|
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
|
|
|
for true {
|
|
|
|
msg := make([]byte, 5120)
|
|
|
|
n, err := ws.Read(msg)
|
|
|
|
|
|
|
|
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(that.Resp, that.Req)
|
|
|
|
},
|
|
|
|
}}})
|
2022-07-11 03:07:17 +00:00
|
|
|
|
|
|
|
}
|