使用Go编写WebAssembly

(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:\progFiles\go\misc\wasm
to e:\go-project

 

2) helloworld.html


    
        "utf-8">
        
        
    
    

 

 

(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++
    }
}

使用Go编写WebAssembly_第1张图片

 开发者工具--》Console

 

 

Reference:

    https://github.com/golang/go/wiki/WebAssembly

 

你可能感兴趣的:(使用Go编写WebAssembly)