• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package main
2
3import (
4	"echo/net"
5	"fmt"
6	"io/ioutil"
7	"net/http"
8)
9
10func echo(w http.ResponseWriter, r *http.Request) {
11	body, err := ioutil.ReadAll(r.Body)
12	if err != nil {
13		fmt.Printf("Unable to read request body: %v\n", err)
14		return
15	}
16
17	req := net.GetRootAsRequest(body, 0)
18	player := req.Player(nil)
19
20	fmt.Printf("Got request (name: %v, hp: %v)\n", string(player.Name()), player.Hp())
21	w.Write(body)
22}
23
24func main() {
25	http.HandleFunc("/echo", echo)
26
27	fmt.Println("Listening on port :8080")
28	http.ListenAndServe(":8080", nil)
29}
30