-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.go
More file actions
51 lines (42 loc) · 1 KB
/
echo.go
File metadata and controls
51 lines (42 loc) · 1 KB
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
45
46
47
48
49
50
51
package main
import (
"net/http"
"os"
"time"
echo "github.com/labstack/echo/v5"
)
type HttpHeader struct {
Name string
Value string
}
func NewHttpHeader(name string, value string) *HttpHeader {
h := &HttpHeader{
Name: name,
Value: value}
return h
}
type DumpResult struct {
Path string `json:"path"`
Time string `json:"time"`
RemoteAddr string `json:"remoteAddr"`
Hostname string `json:"hostname"`
Headers map[string]string `json:"headers"`
}
func dumpRequest(c *echo.Context) error {
r := &DumpResult{}
r.Path = c.Request().RequestURI
r.Hostname, _ = os.Hostname()
r.Time = time.Now().Format(time.RFC3339Nano)
r.RemoteAddr = c.Request().RemoteAddr
r.Headers = make(map[string]string)
for name, values := range c.Request().Header {
for _, v := range values {
r.Headers[name] = v
}
}
appName := os.Getenv("X_APP_NAME")
if appName != "" {
r.Headers["X-Application-Name"] = appName
}
return c.JSON(http.StatusOK, r)
}