-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
157 lines (134 loc) · 4.4 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"log"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/fiber/v2/middleware/logger"
)
type BaseResp struct {
Args map[string]interface{} `json:"args"`
Headers map[string]string `json:"headers"`
Origin string `json:"origin"`
URL string `json:"url"`
Method string `json:"method"`
}
func main() {
app := fiber.New(fiber.Config{
Prefork: false,
CaseSensitive: false,
DisableStartupMessage: false,
ServerHeader: "Fiber-httpbin",
})
app.Use(favicon.New(favicon.Config{
File: "static/favicon.ico",
}))
app.Use(etag.New())
app.Use(logger.New(logger.Config{
TimeZone: "Asia/Shanghai",
TimeFormat: "2006年01月02日15点04分05秒",
}))
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
"TaceyWong": "123",
},
Next: func(c *fiber.Ctx) bool {
if strings.HasPrefix(c.OriginalURL(), "/basic-auth") {
return false
}
return true
},
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Fiber httpbin 👋!")
})
// http methods
app.Get("/get", GetMethod)
app.Post("/post", PostMethod)
app.Put("/put", PutMethod)
app.Patch("/patch", PatchMethod)
app.Delete("/delete", DeleteMethod)
// anything
app.Delete("/anything", DeleteAnything)
app.Get("/anything", GetAnything)
app.Patch("/anything", PatchAnything)
app.Post("/anything", PostAnything)
app.Put("/anything", PutAnything)
app.Delete("/anything/:anything", DeleteAnythingAnything)
app.Get("/anything/:anything", GetAnythingAnything)
app.Patch("/anything/:anything", PatchAnythingAnything)
app.Post("/anything/:anything", PostAnythingAnything)
app.Put("/anything/:anything", PutAnythingAnything)
// redirects
app.Get("/absolute-redirect/:n", GetAbsoluteRedirect)
app.Delete("/redirect-to", RedirectTo)
app.Get("/redirect-to", RedirectTo)
app.Post("/redirect-to", RedirectTo)
app.Patch("/redirect-to", RedirectTo)
app.Put("/redirect-to", RedirectTo)
app.Get("/redirect/:n", RedirectTo)
app.Get("/relative-redirect/:n", GetRelativeRedirect)
// images
app.Get("/image", GetImage)
app.Get("/image/jpeg", GetImageJPEG)
app.Get("/image/jpg", GetImageJPEG)
app.Get("/image/png", GetImagePNG)
app.Get("/image/svg", GetImageSVG)
app.Get("/image/webp", GetImageWebP)
// cookies
app.Get("/cookies", GetCookies)
app.Get("/cookoes/delete", GetCookiesDelete)
app.Get("/cookies/set", GetCookiesSet)
app.Get("/cookies/set/:name/:value", GetCookiesSetValue)
// dynamic data
app.Get("/base64/:value", GetBase64Value)
app.Get("/bytes/:n", GetBytesN)
app.Delete("/delay/:delay", Delay)
app.Get("/delay/:delay", Delay)
app.Post("/delay/:delay", Delay)
app.Patch("/delay/:delay", Delay)
app.Put("/delay/:delay", Delay)
app.Get("/drip", GetDrip)
app.Get("/links/:n/:offset", GetLinks)
app.Get("/range", GetRange)
app.Get("/stream-bytes/:n", GetStreamBytes)
app.Get("/stream/:n", GetStream)
app.Get("/uuid", GetUUID)
// response format
app.Get("/btotli", GetRespBrotli)
app.Get("/deflate", GetRespDeflate)
app.Get("/deny", GetRespDeny)
app.Get("/encoding/utf8", GetRespEncodingUTF8)
app.Get("/gzip", GetRespGZip)
app.Get("/html", GetRespHTML)
app.Get("/json", GetRespJSON)
app.Get("/robors.txt", GetRespRobotsTXT)
app.Get("/xml", GetRespXML)
// response inspection
app.Get("/cache", GetRespCache)
app.Get("/cache/:value", GetRespCacheValue)
app.Get("/etag/:etag", GetRespEtag)
app.Get("/response-headers", GetRespHeaders)
app.Post("/response-headers", PostRespHeaders)
// request inspection
app.Get("/headers", GetHeaders)
app.Get("/ip", GetIP)
app.Get("/user-agent", GetUserAgent)
// status code
app.Delete("/status/:codes", DeleteStatus)
app.Get("/status/:codes", GetStatus)
app.Patch("/status/:codes", PatchStatus)
app.Post("/status/:codes", PostStatus)
app.Put("/status/:codes", PutStatus)
// auth
app.Get("/basic-auth/:user/:passwd", GetBasicAuth)
app.Get("/bearer", GetBearerAuth)
app.Get("/digest-auth/:qop/:user/:passwd", GetDigestAuth)
app.Get("/digest-auth/:qop/:user/:passwd/:algorithm", GetDigestAuthA)
app.Get("/digest-auth/:qop/:user/:passwd/:algorithm/:stale_after", GetDigestAuthAS)
app.Get("/hiden-basic-auth/:user/:passwd", GetHidenBasicAuth)
log.Printf("Start at :3000")
log.Fatal(app.Listen(":3000"))
}