webAssembly nie dziala na windowsie
This commit is contained in:
parent
e7d21df9b3
commit
f005452baf
22
backend/go_concurrency/main.go
Normal file
22
backend/go_concurrency/main.go
Normal 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
|
||||
}
|
12
backend/go_proto_buffer/main.go
Normal file
12
backend/go_proto_buffer/main.go
Normal 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")
|
||||
}
|
4
backend/go_proto_buffer/person.json
Normal file
4
backend/go_proto_buffer/person.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "elliot",
|
||||
"age": 24
|
||||
}
|
4
backend/go_proto_buffer/person.xml
Normal file
4
backend/go_proto_buffer/person.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<person>
|
||||
<name>Elliot</name>
|
||||
<age>24</age>
|
||||
</person>
|
45
backend/go_web_assembly/index.html
Normal file
45
backend/go_web_assembly/index.html
Normal 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>
|
BIN
backend/go_web_assembly/lib.wasm
Normal file
BIN
backend/go_web_assembly/lib.wasm
Normal file
Binary file not shown.
13
backend/go_web_assembly/main.go
Normal file
13
backend/go_web_assembly/main.go
Normal 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")
|
||||
}
|
20
backend/go_web_assembly/server.go
Normal file
20
backend/go_web_assembly/server.go
Normal 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))))
|
||||
}
|
49
backend/go_web_assembly/wasm_exec.html
Normal file
49
backend/go_web_assembly/wasm_exec.html
Normal 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>
|
3935
backend/go_web_assembly/wasm_exec.js
Normal file
3935
backend/go_web_assembly/wasm_exec.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user