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

View File

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

View File

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

Binary file not shown.