This commit is contained in:
Nicolas Lepage
2019-11-27 11:20:52 +01:00
parent 5a9f7c57a2
commit bffb45066d
7 changed files with 99 additions and 13 deletions

9
docs/index.html Normal file
View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
navigator.serviceWorker.register('sw.js')
</script>
</body>
</html>

9
docs/sw.js Normal file
View File

@@ -0,0 +1,9 @@
importScripts(
'https://raw.githubusercontent.com/nlepage/go-wasm-http-server/master/lib/wasm_exec/wasm_exec.js',
'https://raw.githubusercontent.com/nlepage/go-wasm-http-server/master/index.js',
)
wasmhttp.serve({
wasm: 'test.wasm',
base: '/test',
})

28
docs/test.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
wasmhttp "github.com/nlepage/go-wasm-http-server"
)
func main() {
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
params := make(map[string]string)
if err := json.NewDecoder(req.Body).Decode(&params); err != nil {
panic(err)
}
if err := json.NewEncoder(res).Encode(map[string]string{
"message": fmt.Sprintf("Hello %s!", params["name"]),
}); err != nil {
panic(err)
}
})
wasmhttp.Serve(nil)
select {}
}

BIN
docs/test.wasm Executable file

Binary file not shown.