2019-11-27 11:20:52 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2024-10-14 22:24:46 +02:00
|
|
|
wasmhttp "github.com/nlepage/go-wasm-http-server/v2"
|
2019-11-27 11:20:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-01-24 21:18:18 +01:00
|
|
|
res.Header().Add("Content-Type", "application/json")
|
2019-11-27 11:20:52 +01:00
|
|
|
if err := json.NewEncoder(res).Encode(map[string]string{
|
2021-01-21 23:07:42 +01:00
|
|
|
"message": fmt.Sprintf("Hello %s!", params["name"]),
|
2019-11-27 11:20:52 +01:00
|
|
|
}); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-01-22 15:28:37 +01:00
|
|
|
wasmhttp.Serve(nil)
|
2021-01-22 01:36:15 +01:00
|
|
|
|
2021-01-22 15:28:37 +01:00
|
|
|
select {}
|
2019-11-27 11:20:52 +01:00
|
|
|
}
|