This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbindings.go
82 lines (77 loc) · 1.64 KB
/
bindings.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package yoo
import (
"strconv"
"fmt"
"net/http"
)
func getConsole() Any {
var log TSFunction = func (args *[]Any) Any {
for _, v := range *args {
fmt.Print(v, " ")
}
fmt.Println()
return nil
}
return CreateObject(
&[]string{ "log" },
&[]Any{ &log },
)
}
func getHttp() Any {
var newContent ProxyFunction = func (object Any, t int, key string, value Any) Any {
obj := *object.(*HttpContent)
switch key {
case "method":
return obj.r.Method
default:
return nil
}
}
newCtxPtr := &newContent
var Server TSFunction = func (argsPtr *[]Any) Any {
args := *argsPtr
length := len(args)
var server *http.Server
if length == 0 {
server = &http.Server {}
} else if handlerPtr, ok := args[0].(*TSFunction); ok {
handle := *handlerPtr
var h http.HandlerFunc = func (w http.ResponseWriter, r *http.Request) {
handle(&[]Any { &Proxy{ &HttpContent { &w, r }, newCtxPtr } })
}
port := 80
if length > 1 {
if p, ok := args[1].(float64); ok {
port = int(p)
}
}
server = &http.Server {
Addr: "127.0.0.1:" + strconv.Itoa(port),
Handler: h,
}
}
var obj Any
var listen TSFunction = func (args *[]Any) Any {
server.ListenAndServe()
return obj
}
obj = &Object4 {
k0: "listen",
v0: &listen,
}
return obj
}
return CreateObject(
&[]string{ "Server" },
&[]Any{ &Server },
)
}
func GetBindings() *Variables {
return &Variables {
"net/http": getHttp(),
}
}
type HttpContent struct {
w *http.ResponseWriter
r *http.Request
}