mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-11 01:29:11 +00:00
⚗️
This commit is contained in:
parent
0a1eee9812
commit
5f09cb3c8a
13
docs/api.go
13
docs/api.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
wasmhttp "github.com/nlepage/go-wasm-http-server"
|
wasmhttp "github.com/nlepage/go-wasm-http-server"
|
||||||
)
|
)
|
||||||
@ -11,9 +12,10 @@ import (
|
|||||||
var no = 1
|
var no = 1
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Starting...")
|
|
||||||
|
|
||||||
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
h, m, s := time.Now().Clock()
|
||||||
|
fmt.Printf("hello at %02d:%02d:%02d\n", h, m, s)
|
||||||
|
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
if err := json.NewDecoder(req.Body).Decode(¶ms); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(¶ms); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -29,7 +31,12 @@ func main() {
|
|||||||
|
|
||||||
wasmhttp.Serve(nil)
|
wasmhttp.Serve(nil)
|
||||||
|
|
||||||
fmt.Println("Started")
|
go func() {
|
||||||
|
for range time.Tick(time.Second) {
|
||||||
|
h, m, s := time.Now().Clock()
|
||||||
|
fmt.Printf("tick at %02d:%02d:%02d\n", h, m, s)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
BIN
docs/api.wasm
BIN
docs/api.wasm
Binary file not shown.
2
sw.js
2
sw.js
@ -64,7 +64,7 @@ addEventListener('message', async ({ data }) => {
|
|||||||
startWasm(wasm, handlerId, path)
|
startWasm(wasm, handlerId, path)
|
||||||
running.add(key)
|
running.add(key)
|
||||||
|
|
||||||
// FIXME try catch
|
// FIXME try catch
|
||||||
handlers.push([path, await handler])
|
handlers.push([path, await handler])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user