1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00

Update to go binary

This commit is contained in:
Johan Brandhorst 2018-10-14 15:31:09 +01:00
parent fc4b173370
commit 5a07f70561
No known key found for this signature in database
GPG Key ID: 266C7D9B44EAA057
4 changed files with 27 additions and 22 deletions

View File

@ -1,36 +1,36 @@
.PHONY: hello
hello:
rm -f ./html/*
GOOS=js GOARCH=wasm go1.11rc2 build -o ./html/test.wasm ./hello/main.go
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
GOOS=js GOARCH=wasm go build -o ./html/test.wasm ./hello/main.go
cp $$(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
.PHONY: channels
channels:
rm -f ./html/*
GOOS=js GOARCH=wasm go1.11rc2 build -o ./html/test.wasm ./channels/main.go
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
GOOS=js GOARCH=wasm go build -o ./html/test.wasm ./channels/main.go
cp $$(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
.PHONY: js
js:
rm -f ./html/*
GOOS=js GOARCH=wasm go1.11rc2 build -o ./html/test.wasm ./js/main.go
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
GOOS=js GOARCH=wasm go build -o ./html/test.wasm ./js/main.go
cp $$(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
sed -i -e 's;</button>;</button>\n\t<div id=\"target\"></div>;' ./html/index.html
.PHONY: fetch
fetch:
rm -f ./html/*
GOOS=js GOARCH=wasm go1.11rc2 build -o ./html/test.wasm ./fetch/main.go
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go1.11rc2 env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
GOOS=js GOARCH=wasm go build -o ./html/test.wasm ./fetch/main.go
cp $$(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
sed -i -e 's;</button>;</button>\n\t<div id=\"target\"></div>;' ./html/index.html
.PHONY: jsgo
jsgo:
wasmgo -c=go1.11rc2 deploy github.com/johanbrandhorst/wasm-experiments/jsgo
wasmgo -c=go deploy github.com/johanbrandhorst/wasm-experiments/jsgo
serve:
go run main.go

View File

@ -4,4 +4,4 @@ Just some playing around with the new experimental Go WASM arch target
## Requirements
Requires `go1.11rc2`
Requires `go` 1.11

View File

@ -7,23 +7,28 @@ import (
"log"
"net/http"
"strings"
"github.com/dennwc/dom"
"syscall/js"
)
type writer dom.Element
var document js.Value
func init() {
document = js.Global().Get("document")
}
type writer js.Value
// Write implements io.Writer.
func (d writer) Write(p []byte) (n int, err error) {
node := dom.GetDocument().CreateElement("div")
node.SetTextContent(string(p))
(*dom.Element)(&d).AppendChild(node)
node := document.Call("createElement", "div")
node.Set("textContent", string(p))
js.Value(d).Call("appendChild", node)
return len(p), nil
}
func main() {
t := dom.GetDocument().GetElementById("target")
logger := log.New((*writer)(t), "", log.LstdFlags)
t := document.Call("getElementById", "target")
logger := log.New((*writer)(&t), "", log.LstdFlags)
c := http.Client{}
req, err := http.NewRequest(

Binary file not shown.