Skip to content

Commit feb7c59

Browse files
authored
Merge pull request #252 from Fenny/master
v1.8.431
2 parents f60c61c + 79c378c commit feb7c59

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

fiber.go app.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const Version = "1.8.43"
2929
// Map is a shortcut for map[string]interface{}
3030
type Map map[string]interface{}
3131

32-
// Fiber denotes the Fiber application.
33-
type Fiber struct {
32+
// App denotes the Fiber application.
33+
type App struct {
3434
server *fasthttp.Server // FastHTTP server
3535
routes []*Route // Route stack
3636
Settings *Settings // Fiber settings
@@ -67,15 +67,15 @@ type Settings struct {
6767
// Group struct
6868
type Group struct {
6969
prefix string
70-
app *Fiber
70+
app *App
7171
}
7272

7373
// Global variables
7474
var isPrefork, isChild bool
7575

7676
// New creates a new Fiber named instance.
7777
// You can pass optional settings when creating a new instance.
78-
func New(settings ...*Settings) *Fiber {
78+
func New(settings ...*Settings) *App {
7979
// Parse arguments
8080
for _, v := range os.Args[1:] {
8181
if v == "-prefork" {
@@ -85,7 +85,7 @@ func New(settings ...*Settings) *Fiber {
8585
}
8686
}
8787
// Create app
88-
app := new(Fiber)
88+
app := new(App)
8989
// Create settings
9090
app.Settings = new(Settings)
9191
// Set default settings
@@ -109,7 +109,7 @@ func New(settings ...*Settings) *Fiber {
109109
}
110110

111111
// Group is used for Routes with common prefix to define a new sub-router with optional middleware.
112-
func (app *Fiber) Group(prefix string, handlers ...func(*Ctx)) *Group {
112+
func (app *App) Group(prefix string, handlers ...func(*Ctx)) *Group {
113113
if len(handlers) > 0 {
114114
app.registerMethod("USE", prefix, handlers...)
115115
}
@@ -139,15 +139,15 @@ type Static struct {
139139
}
140140

141141
// Static registers a new route with path prefix to serve static files from the provided root directory.
142-
func (app *Fiber) Static(prefix, root string, config ...Static) *Fiber {
142+
func (app *App) Static(prefix, root string, config ...Static) *App {
143143
app.registerStatic(prefix, root, config...)
144144
return app
145145
}
146146

147147
// Use registers a middleware route.
148148
// Middleware matches requests beginning with the provided prefix.
149149
// Providing a prefix is optional, it defaults to "/"
150-
func (app *Fiber) Use(args ...interface{}) *Fiber {
150+
func (app *App) Use(args ...interface{}) *App {
151151
var path = ""
152152
var handlers []func(*Ctx)
153153
for i := 0; i < len(args); i++ {
@@ -165,61 +165,61 @@ func (app *Fiber) Use(args ...interface{}) *Fiber {
165165
}
166166

167167
// Connect : https://fiber.wiki/application#http-methods
168-
func (app *Fiber) Connect(path string, handlers ...func(*Ctx)) *Fiber {
168+
func (app *App) Connect(path string, handlers ...func(*Ctx)) *App {
169169
app.registerMethod(MethodConnect, path, handlers...)
170170
return app
171171
}
172172

173173
// Put : https://fiber.wiki/application#http-methods
174-
func (app *Fiber) Put(path string, handlers ...func(*Ctx)) *Fiber {
174+
func (app *App) Put(path string, handlers ...func(*Ctx)) *App {
175175
app.registerMethod(MethodPut, path, handlers...)
176176
return app
177177
}
178178

179179
// Post : https://fiber.wiki/application#http-methods
180-
func (app *Fiber) Post(path string, handlers ...func(*Ctx)) *Fiber {
180+
func (app *App) Post(path string, handlers ...func(*Ctx)) *App {
181181
app.registerMethod(MethodPost, path, handlers...)
182182
return app
183183
}
184184

185185
// Delete : https://fiber.wiki/application#http-methods
186-
func (app *Fiber) Delete(path string, handlers ...func(*Ctx)) *Fiber {
186+
func (app *App) Delete(path string, handlers ...func(*Ctx)) *App {
187187
app.registerMethod(MethodDelete, path, handlers...)
188188
return app
189189
}
190190

191191
// Head : https://fiber.wiki/application#http-methods
192-
func (app *Fiber) Head(path string, handlers ...func(*Ctx)) *Fiber {
192+
func (app *App) Head(path string, handlers ...func(*Ctx)) *App {
193193
app.registerMethod(MethodHead, path, handlers...)
194194
return app
195195
}
196196

197197
// Patch : https://fiber.wiki/application#http-methods
198-
func (app *Fiber) Patch(path string, handlers ...func(*Ctx)) *Fiber {
198+
func (app *App) Patch(path string, handlers ...func(*Ctx)) *App {
199199
app.registerMethod(MethodPatch, path, handlers...)
200200
return app
201201
}
202202

203203
// Options : https://fiber.wiki/application#http-methods
204-
func (app *Fiber) Options(path string, handlers ...func(*Ctx)) *Fiber {
204+
func (app *App) Options(path string, handlers ...func(*Ctx)) *App {
205205
app.registerMethod(MethodOptions, path, handlers...)
206206
return app
207207
}
208208

209209
// Trace : https://fiber.wiki/application#http-methods
210-
func (app *Fiber) Trace(path string, handlers ...func(*Ctx)) *Fiber {
210+
func (app *App) Trace(path string, handlers ...func(*Ctx)) *App {
211211
app.registerMethod(MethodTrace, path, handlers...)
212212
return app
213213
}
214214

215215
// Get : https://fiber.wiki/application#http-methods
216-
func (app *Fiber) Get(path string, handlers ...func(*Ctx)) *Fiber {
216+
func (app *App) Get(path string, handlers ...func(*Ctx)) *App {
217217
app.registerMethod(MethodGet, path, handlers...)
218218
return app
219219
}
220220

221221
// All matches all HTTP methods and complete paths
222-
func (app *Fiber) All(path string, handlers ...func(*Ctx)) *Fiber {
222+
func (app *App) All(path string, handlers ...func(*Ctx)) *App {
223223
app.registerMethod("ALL", path, handlers...)
224224
return app
225225
}
@@ -325,7 +325,7 @@ func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
325325

326326
// Listen serves HTTP requests from the given addr or port.
327327
// You can pass an optional *tls.Config to enable TLS.
328-
func (app *Fiber) Listen(address interface{}, tlsconfig ...*tls.Config) error {
328+
func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
329329
addr, ok := address.(string)
330330
if !ok {
331331
port, ok := address.(int)
@@ -370,7 +370,7 @@ func (app *Fiber) Listen(address interface{}, tlsconfig ...*tls.Config) error {
370370
// Make sure the program doesn't exit and waits instead for Shutdown to return.
371371
//
372372
// Shutdown does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.
373-
func (app *Fiber) Shutdown() error {
373+
func (app *App) Shutdown() error {
374374
if app.server == nil {
375375
return fmt.Errorf("Server is not running")
376376
}
@@ -379,7 +379,7 @@ func (app *Fiber) Shutdown() error {
379379

380380
// Test is used for internal debugging by passing a *http.Request.
381381
// Timeout is optional and defaults to 200ms, -1 will disable it completely.
382-
func (app *Fiber) Test(request *http.Request, msTimeout ...int) (*http.Response, error) {
382+
func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, error) {
383383
timeout := 200
384384
if len(msTimeout) > 0 {
385385
timeout = msTimeout[0]
@@ -426,7 +426,7 @@ func (app *Fiber) Test(request *http.Request, msTimeout ...int) (*http.Response,
426426
}
427427

428428
// Sharding: https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/
429-
func (app *Fiber) prefork(address string) (ln net.Listener, err error) {
429+
func (app *App) prefork(address string) (ln net.Listener, err error) {
430430
// Master proc
431431
if !isChild {
432432
addr, err := net.ResolveTCPAddr("tcp", address)
@@ -474,7 +474,7 @@ func (dl *disableLogger) Printf(format string, args ...interface{}) {
474474
// fmt.Println(fmt.Sprintf(format, args...))
475475
}
476476

477-
func (app *Fiber) newServer() *fasthttp.Server {
477+
func (app *App) newServer() *fasthttp.Server {
478478
return &fasthttp.Server{
479479
Handler: app.handler,
480480
Name: app.Settings.ServerHeader,

fiber_test.go app_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
var handler = func(c *Ctx) {}
1313

14-
func is200(t *testing.T, app *Fiber, url string, m ...string) {
14+
func is200(t *testing.T, app *App, url string, m ...string) {
1515

1616
method := "GET"
1717
if len(m) > 0 {

ctx.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// Ctx represents the Context which hold the HTTP request and response.
2929
// It has methods for the request query string, parameters, body, HTTP headers and so on.
3030
type Ctx struct {
31-
app *Fiber // Reference to *Fiber
31+
app *App // Reference to *App
3232
route *Route // Reference to *Route
3333
index int // Index of the current stack
3434
method string // HTTP method
@@ -831,5 +831,5 @@ func (ctx *Ctx) Write(bodies ...interface{}) {
831831
// XHR returns a Boolean property, that is true, if the request’s X-Requested-With header field is XMLHttpRequest,
832832
// indicating that the request was issued by a client library (such as jQuery).
833833
func (ctx *Ctx) XHR() bool {
834-
return ctx.Get(HeaderXRequestedWith) == "XMLHttpRequest"
834+
return strings.ToLower(ctx.Get(HeaderXRequestedWith)) == "xmlhttprequest"
835835
}

router.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Route struct {
3131
Handler func(*Ctx) // ctx handler
3232
}
3333

34-
func (app *Fiber) nextRoute(ctx *Ctx) {
34+
func (app *App) nextRoute(ctx *Ctx) {
3535
// Keep track of head matches
3636
lenr := len(app.routes) - 1
3737
for ctx.index < lenr {
@@ -101,7 +101,7 @@ func (r *Route) matchRoute(method, path string) (match bool, values []string) {
101101
return false, values
102102
}
103103

104-
func (app *Fiber) handler(fctx *fasthttp.RequestCtx) {
104+
func (app *App) handler(fctx *fasthttp.RequestCtx) {
105105
// get fiber context from sync pool
106106
ctx := acquireCtx(fctx)
107107
defer releaseCtx(ctx)
@@ -120,7 +120,7 @@ func (app *Fiber) handler(fctx *fasthttp.RequestCtx) {
120120
app.nextRoute(ctx)
121121
}
122122

123-
func (app *Fiber) registerMethod(method, path string, handlers ...func(*Ctx)) {
123+
func (app *App) registerMethod(method, path string, handlers ...func(*Ctx)) {
124124
// Route requires atleast one handler
125125
if len(handlers) == 0 {
126126
log.Fatalf("Missing handler in route")
@@ -185,7 +185,7 @@ func (app *Fiber) registerMethod(method, path string, handlers ...func(*Ctx)) {
185185
}
186186
}
187187

188-
func (app *Fiber) registerStatic(prefix, root string, config ...Static) {
188+
func (app *App) registerStatic(prefix, root string, config ...Static) {
189189
// Cannot have an empty prefix
190190
if prefix == "" {
191191
prefix = "/"

0 commit comments

Comments
 (0)