-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp-server.go
More file actions
44 lines (35 loc) · 745 Bytes
/
http-server.go
File metadata and controls
44 lines (35 loc) · 745 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
42
43
44
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
type Body struct {
Name string `json:"name"`
Request Request `json:"request"`
}
type Request struct {
Url string `json:"url"`
Method string `json:"method"`
Header map[string][]string `json:"headers"`
}
func name() string {
return os.Getenv("NAME")
}
func info(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
body := Body{
Name: name(),
Request: Request{
Url: req.URL.String(),
Method: req.Method,
Header: req.Header,
}}
json.NewEncoder(w).Encode(body)
}
func main() {
http.HandleFunc("/", info)
fmt.Println("start", name())
http.ListenAndServe(":8080", nil)
}