blob: 2fcd1ec2fc1d750f382331ae1c9248198edaf09d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello folks!")
})
mux.HandleFunc("/payload", handleRequest)
http.ListenAndServe(":8080", mux)
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
bytes, err := io.ReadAll(io.Reader(r.Body))
if err != nil {
panic(err)
}
fmt.Fprint(w, "Hello, World!", string(bytes))
log.Println("Request received", r.RemoteAddr, string(bytes))
}
|