(Windows10 WSL)
I. Install go
see 《install go on ubuntu》
II. go wasm
1. compile
set GOARCH=wasm set GOOS=js go build -o helloworld.wasm helloworld.go
2. set mime type
/etc/mime.types
Ln132:
application/wasm wasm
3. run
(1) other files
1) wasm_exec
from E:progFilesgomiscwasm
to e:go-project
2) helloworld.html
<html> <head> <meta charset="utf-8"> <script src="wasm_exec.js"></script> <script> const go = new Go(); WebAssembly.instantiateStreaming(fetch("helloworld.wasm"), go.importObject).then((result) => { go.run(result.instance); }); </script> </head> <body></body> </html>
(2) exec
cd /mnt/e/go-project
python -m SimpleHTTPServer 8080
http://localhost:8080/helloworld.html
src: helloworld.go
package main import ( "fmt" ) func main() { var str string var i = 1 str = "Hello, WebAssembly!" for i < 10 { fmt.Println(str, i) i++ } }
开发者工具--》Console
Reference:
https://github.com/golang/go/wiki/WebAssembly