webAssembly nie dziala na windowsie

This commit is contained in:
monastyr 2018-11-16 20:55:41 +01:00
parent e7d21df9b3
commit f005452baf
10 changed files with 4104 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"time"
)
func compute(value int) {
for i := 0; i < value; i++ {
time.Sleep(time.Second)
fmt.Println(i)
}
}
func main() {
fmt.Println("Concurrency With GoRoutines")
go compute(5) //asynchroniczne wywolania goutis routine
go compute(5)
fmt.Scanln() //zeby petla glowa(main) nie zakoncyl sie przed watkami
}

View File

@ -0,0 +1,12 @@
package main
//stat -f%z person.xml nie dziala :<
// go get github.com/golang/protobuf
//[!] błąd [!] can't load package: package github.com/golang/protobuf: no Go files in C:\Users\dp\go\src\github.com\golang\protobuf
//go get github.com/golang/protobuf/proto
import "fmt"
func main() {
fmt.Println("Hello World")
}

View File

@ -0,0 +1,4 @@
{
"name": "elliot",
"age": 24
}

View File

@ -0,0 +1,4 @@
<person>
<name>Elliot</name>
<age>24</age>
</person>

View File

@ -0,0 +1,45 @@
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<title>Go wasm</title>
</head>
<body>
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("lib.wasm"), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
document.getElementById("runButton").disabled = false;
});
async function run() {
await go.run(inst);
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
}
</script>
<button onClick="run();" id="runButton" disabled>Run</button>
</body>
</html>

Binary file not shown.

View File

@ -0,0 +1,13 @@
package main
//[!] DOESNT WORK ON WINDOWS [!]
//backend dla frontu webowego
//GOARCH=wasm GOOS=js go build -o lib.wasm main.go
// go env
// set GOARCH=wasm
// set GOOS=js
// go build -o lib.wasm main.go
func main() {
println("Hello World")
}

View File

@ -0,0 +1,20 @@
//simple server
package main
import (
"flag"
"log"
"net/http"
)
var (
listen = flag.String("listen", ":8080", "listen address")
dir = flag.String("dir", ".", "directory to serve")
)
func main() {
flag.Parse()
log.Printf("Listening on %q...", *listen)
log.Fatal(http.ListenAndServe(*listen, http.FileServer(http.Dir(*dir))))
}

View File

@ -0,0 +1,49 @@
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<title>Go wasm</title>
</head>
<body>
<!--
Add the following polyfill for Microsoft Edge 17/18 support:
<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.7.0/lib/encoding.min.js"></script>
(see https://caniuse.com/#feat=textencoder)
-->
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
document.getElementById("runButton").disabled = false;
}).catch((err) => {
console.error(err);
});
async function run() {
console.clear();
await go.run(inst);
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
}
</script>
<button onClick="run();" id="runButton" disabled>Run</button>
</body>
</html>

File diff suppressed because it is too large Load Diff