2019-11-27 11:20:52 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2020-05-29 00:40:28 +02:00
|
|
|
"time"
|
2019-11-27 11:20:52 +01:00
|
|
|
|
|
|
|
wasmhttp "github.com/nlepage/go-wasm-http-server"
|
|
|
|
)
|
|
|
|
|
2019-12-02 17:22:48 +01:00
|
|
|
var no = 1
|
|
|
|
|
2019-11-27 11:20:52 +01:00
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
|
2020-05-29 00:40:28 +02:00
|
|
|
h, m, s := time.Now().Clock()
|
|
|
|
fmt.Printf("hello at %02d:%02d:%02d\n", h, m, s)
|
|
|
|
|
2019-11-27 11:20:52 +01:00
|
|
|
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{
|
2019-12-02 17:22:48 +01:00
|
|
|
"message": fmt.Sprintf("Hello %s! (%d)", params["name"], no),
|
2019-11-27 11:20:52 +01:00
|
|
|
}); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-12-02 17:22:48 +01:00
|
|
|
no++
|
2019-11-27 11:20:52 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
wasmhttp.Serve(nil)
|
|
|
|
|
2020-05-29 00:40:28 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}()
|
2020-05-28 23:51:54 +02:00
|
|
|
|
2019-11-27 11:20:52 +01:00
|
|
|
select {}
|
|
|
|
}
|