forked from paddycarey/go-echo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (35 loc) · 800 Bytes
/
Copy pathmain.go
File metadata and controls
41 lines (35 loc) · 800 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
)
type request struct {
URL string `json:"url"`
Method string `json:"method"`
Headers http.Header `json:"headers"`
Body []byte `json:"body"`
}
func handle(rw http.ResponseWriter, r *http.Request) {
var err error
rr := &request{}
rr.Method = r.Method
rr.Headers = r.Header
rr.URL = r.URL.String()
rr.Body, err = ioutil.ReadAll(r.Body)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
rrb, err := json.Marshal(rr)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(rrb)
}
func main() {
http.HandleFunc("/", handle)
http.ListenAndServe(":8000", nil)
}