hotime/example/main.go
2022-07-11 19:13:20 +08:00

49 lines
1.1 KiB
Go

package main
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"fmt"
"golang.org/x/net/websocket"
)
func main() {
appIns := Init("config/config.json")
appIns.Run(Router{"app": Proj{
"user": Ctr{
"test": func(that *Context) {
fmt.Println("dasdasd")
//id := that.Db.Insert("user", Map{"name": "test"})
//ok := that.Db.Update("user", Map{"name": "test1"}, Map{"name": "test"})
ps := that.Db.Select("user", "*")
p := that.Db.Get("user", "*")
//row := that.Db.Delete("user", Map{"id": id})
//that.Display(0, Slice{id, ok, ps, p, row})
that.Display(0, Slice{ps, p})
},
"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)
},
}}})
}