(Windows10 WSL) html
set GOARCH=wasm set GOOS=js go build -o helloworld.wasm helloworld.go
/etc/mime.types
Ln132:python
application/wasm wasm
(1) other filesgit
1) wasm_exec
from E:\progFiles\go\misc\wasm
to e:\go-projectgithub
2) helloworld.htmlgolang
<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) execubuntu
cd /mnt/e/go-project
python -m SimpleHTTPServer 8080
http://localhost:8080/helloworld.htmlapp
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++ } }
開發者工具--》Consolepost
Reference:fetch
https://github.com/golang/go/wiki/WebAssembly