-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsobj.go
45 lines (38 loc) · 868 Bytes
/
jsobj.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
// +build js
//compile with gopherjs build -m
package main
import (
"bytes"
"github.com/empijei/identigen/identities"
"github.com/gopherjs/gopherjs/js"
)
func main() {
js.Global.Set("identigen", map[string]interface{}{
"RandomPeople": RandomPeopleJS,
"MainModule": MainModuleJS,
})
}
func RandomPeopleJS(minage, maxage int, count int) *js.Object {
ppl, err := identities.RandomPeople(minage, maxage, count)
if err != nil {
panic(err)
}
return js.MakeWrapper(ppl)
}
func MainModuleJS(args map[string]interface{}) string {
out := bytes.NewBuffer(nil)
//<rant>
//I officially hate javascript for the following code
for key, value := range args {
switch value := value.(type) {
case float64:
args[key] = int(value)
}
}
//</rant>
err := identities.MainModule(args, out)
if err != nil {
panic(err)
}
return string(out.Bytes())
}