Size: 130
Comment:
|
Size: 3206
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
{{{ | The Go programming language is an open source project to make programmers more productive. Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language. * https://golang.org/ * https://golang.org/pkg/ * https://tour.golang.org/list * https://tour.golang.org/concurrency/1 * https://learnxinyminutes.com/docs/go/ * https://github.com/golang/go/wiki/WebAssembly#introduction '''Hello world''' {{{#!highlight go |
Line 13: | Line 25: |
== List of GOOS and GOARCH == * go tool dist list Some elements of the list {{{ android/386 android/amd64 android/arm android/arm64 darwin/386 darwin/amd64 darwin/arm darwin/arm64 freebsd/386 freebsd/amd64 freebsd/arm js/wasm linux/386 linux/amd64 linux/arm linux/arm64 netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm windows/386 windows/amd64 }}} == WebAssembly == * On debian buster {{{#!highlight sh sudo apt install golang # go version go1.11.6 linux/amd64 sudo apt install golang-src mkdir ~/wasmgotest }}} '''build.sh''' {{{#!highlight sh go build -o main main.go GOOS=js GOARCH=wasm go build -o main.wasm main.go }}} '''index.html''' {{{#!highlight html <html> <head> <meta charset="utf-8"/> <script src="wasm_exec.js"></script> <script> const go = new Go(); WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => { go.run(result.instance); }); </script> </head> <body> <h1 id="datetimeHeading">5555</h1> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"> </canvas> </body> </html> }}} '''main.go''' {{{ package main //import "fmt" import "time" import "syscall/js" func showTime(){ for x := 0; ; x++ { // infinite loop currentTime := time.Now() // console.log in the browser //fmt.Printf("Hello, WebAssembly %s ! \n" , currentTime.String() ) document := js.Global().Get("document") document.Call("getElementById", "datetimeHeading").Set("innerHTML", currentTime.String()) //document.getElementById("datetimeHeading").innerHTML="aaa" time.Sleep( 2 * time.Second ) } } func main() { go showTime() // go routine executes the called function as a lightweight thread document := js.Global().Get("document") c := document.Call("getElementById","myCanvas") ctx := c.Call("getContext","2d") ctx.Call("beginPath") ctx.Call("arc","95", "50", "40", "0", "6.283") ctx.Call("stroke"); time.Sleep(24*time.Hour) } }}} * cp /usr/share/go-1.11/misc/wasm/wasm_exec.js . * Check on the browser file:///home/vitor/wasmgotest/index.html |
golang
Go programmmig language
The Go programming language is an open source project to make programmers more productive.
Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
Hello world
List of GOOS and GOARCH
- go tool dist list
Some elements of the list
android/386 android/amd64 android/arm android/arm64 darwin/386 darwin/amd64 darwin/arm darwin/arm64 freebsd/386 freebsd/amd64 freebsd/arm js/wasm linux/386 linux/amd64 linux/arm linux/arm64 netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm windows/386 windows/amd64
WebAssembly
- On debian buster
build.sh
index.html
1 <html>
2 <head>
3 <meta charset="utf-8"/>
4 <script src="wasm_exec.js"></script>
5 <script>
6 const go = new Go();
7 WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
8 go.run(result.instance);
9 });
10 </script>
11 </head>
12 <body>
13 <h1 id="datetimeHeading">5555</h1>
14 <canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">
15 </canvas>
16 </body>
17 </html>
main.go
package main //import "fmt" import "time" import "syscall/js" func showTime(){ for x := 0; ; x++ { // infinite loop currentTime := time.Now() // console.log in the browser //fmt.Printf("Hello, WebAssembly %s ! \n" , currentTime.String() ) document := js.Global().Get("document") document.Call("getElementById", "datetimeHeading").Set("innerHTML", currentTime.String()) //document.getElementById("datetimeHeading").innerHTML="aaa" time.Sleep( 2 * time.Second ) } } func main() { go showTime() // go routine executes the called function as a lightweight thread document := js.Global().Get("document") c := document.Call("getElementById","myCanvas") ctx := c.Call("getContext","2d") ctx.Call("beginPath") ctx.Call("arc","95", "50", "40", "0", "6.283") ctx.Call("stroke"); time.Sleep(24*time.Hour) }
- cp /usr/share/go-1.11/misc/wasm/wasm_exec.js .
Check on the browser file:///home/vitor/wasmgotest/index.html