forked from FIPress/GoUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
50 lines (41 loc) · 817 Bytes
/
request.go
File metadata and controls
50 lines (41 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package goui
import "C"
import (
"encoding/json"
)
type Request struct {
Url string `json:"url"`
IsCallback bool `json:"isCallback"`
Context `json:",inline"`
}
var cbMap = make(map[string]func(string))
//export handleClientReq
func handleClientReq(msg *C.char) {
message := C.GoString(msg)
println("ClientHandler:", message)
req := new(Request)
err := json.Unmarshal([]byte(message), req)
if err != nil {
Log("unmarshal error:", err)
return
}
if req.IsCallback {
f := cbMap[req.Url]
if f != nil {
f(req.Data)
delete(cbMap, req.Url)
}
} else {
ctx := &req.Context
handler, params := dispatch(req.Url)
if handler != nil {
ctx.params = params
handler(ctx)
} else {
notFound(ctx)
}
}
}
func notFound(ctx *Context) {
ctx.Error("Function not found ")
}