-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.go
45 lines (37 loc) · 904 Bytes
/
methods.go
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
package main
import (
"net/url"
"github.com/gofiber/fiber/v2"
)
func GetRespContent(c *fiber.Ctx) BaseResp {
resp := BaseResp{}
resp.Method = c.Method()
resp.Origin = c.IP()
resp.URL = c.Context().URI().String()
resp.Headers = map[string]string{}
c.Request().Header.VisitAll(func(k, v []byte) {
resp.Headers[string(k)] = string(v)
})
args := c.Context().QueryArgs().String()
querys, _ := url.ParseQuery(args)
resp.Args = map[string]interface{}{}
for k, v := range querys {
resp.Args[k] = v
}
return resp
}
func GetMethod(c *fiber.Ctx) error {
return c.JSON(GetRespContent(c))
}
func PostMethod(c *fiber.Ctx) error {
return c.JSON(GetRespContent(c))
}
func PutMethod(c *fiber.Ctx) error {
return c.JSON(GetRespContent(c))
}
func PatchMethod(c *fiber.Ctx) error {
return c.JSON(GetRespContent(c))
}
func DeleteMethod(c *fiber.Ctx) error {
return c.JSON(GetRespContent(c))
}