30 lines
576 B
Go
Raw Normal View History

2019-11-27 11:20:52 +01:00
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)
}
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 15:28:37 +01:00
select {}
2019-11-27 11:20:52 +01:00
}