mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2026-01-12 01:59:14 +00:00
⚗️
This commit is contained in:
9
docs/index.html
Normal file
9
docs/index.html
Normal 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
9
docs/sw.js
Normal 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
28
docs/test.go
Normal 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(¶ms); 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
BIN
docs/test.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user