🚚 Move hello to its own dir

This commit is contained in:
Nicolas Lepage
2021-01-22 15:28:37 +01:00
parent 078ff3547e
commit d9eacdc8e1
4 changed files with 5 additions and 17 deletions

28
docs/hello/api.go Normal file
View 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(&params); 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 {}
}