File tree Expand file tree Collapse file tree
src/Servers/TraefikServer/echo Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package main
22
33import (
4- "fmt "
4+ "io "
55 "net/http"
6- "strings"
76)
87
98func main () {
10- http .HandleFunc ("/echo" , func (w http.ResponseWriter , r * http.Request ) {
11- w .Header ().Set ("Content-Type" , "text/plain" )
12- var sb strings.Builder
13- for name , values := range r .Header {
14- for _ , v := range values {
15- sb .WriteString (fmt .Sprintf ("%s: %s\n " , name , v ))
16- }
9+ http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
10+ if r .Method != http .MethodPost {
11+ http .Error (w , "Method Not Allowed" , http .StatusMethodNotAllowed )
12+ return
13+ }
14+
15+ body , err := io .ReadAll (r .Body )
16+ if err != nil {
17+ http .Error (w , "Failed to read body" , http .StatusBadRequest )
18+ return
1719 }
18- fmt .Fprint (w , sb .String ())
20+ defer r .Body .Close ()
21+
22+ w .Header ().Set ("Content-Type" , "text/plain" )
23+ w .WriteHeader (http .StatusOK )
24+ w .Write (body )
1925 })
26+
2027 http .ListenAndServe (":9090" , nil )
2128}
You can’t perform that action at this time.
0 commit comments