-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
38 lines (32 loc) · 835 Bytes
/
main.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
package main
import (
"fmt"
"syscall/js"
"github.com/po3rin/dockerdot/docker2dot"
)
func registerCallbacks() {
var cb js.Func
document := js.Global().Get("document")
element := document.Call("getElementById", "textarea")
cb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
text := element.Get("value").String()
dockerfile := []byte(text)
// https://github.com/golang/go/issues/26382
// should wrap func with gorutine.
go func() {
dot, err := docker2dot.Docker2Dot(dockerfile)
if err != nil {
fmt.Println(err)
}
showGraph := js.Global().Get("showGraph")
showGraph.Invoke(string(dot))
}()
return nil
})
js.Global().Get("document").Call("getElementById", "button").Call("addEventListener", "click", cb)
}
func main() {
c := make(chan struct{}, 0)
registerCallbacks()
<-c
}