Skip to content

Commit 520d2ce

Browse files
authored
Merge pull request #224 from Fenny/master
v1.8.3
2 parents cc70950 + 415a09a commit 520d2ce

14 files changed

+167
-74
lines changed

app.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package fiber
77
import (
88
"bufio"
99
"crypto/tls"
10-
"flag"
1110
"fmt"
1211
"io/ioutil"
1312
"log"
@@ -26,7 +25,7 @@ import (
2625
)
2726

2827
// Version of Fiber
29-
const Version = "1.8.2"
28+
const Version = "1.8.3"
3029

3130
type (
3231
// App denotes the Fiber application.
@@ -51,6 +50,7 @@ type (
5150
ServerHeader string `default:""`
5251
// Enables handler values to be immutable even if you return from handler
5352
Immutable bool `default:"false"`
53+
// Deprecated v1.8.2
5454
// Enables GZip / Deflate compression for all responses
5555
Compression bool `default:"false"`
5656
// Max body size that the server accepts
@@ -64,11 +64,6 @@ type (
6464
}
6565
)
6666

67-
func init() {
68-
flag.Bool("prefork", false, "Use prefork")
69-
flag.Bool("child", false, "Is a child process")
70-
}
71-
7267
// New : https://fiber.wiki/application#new
7368
func New(settings ...*Settings) *App {
7469
var prefork, child bool
@@ -90,17 +85,21 @@ func New(settings ...*Settings) *App {
9085
}
9186
// If settings exist, set some defaults
9287
if len(settings) > 0 {
93-
if !settings[0].Prefork { // Default to -prefork flag if false
94-
settings[0].Prefork = prefork
88+
app.Settings = settings[0] // Set custom settings
89+
if !app.Settings.Prefork { // Default to -prefork flag if false
90+
app.Settings.Prefork = prefork
9591
}
96-
if settings[0].BodyLimit == 0 { // Default MaxRequestBodySize
97-
settings[0].BodyLimit = 4 * 1024 * 1024
92+
if app.Settings.BodyLimit == 0 { // Default MaxRequestBodySize
93+
app.Settings.BodyLimit = 4 * 1024 * 1024
9894
}
99-
if settings[0].Immutable { // Replace unsafe conversion funcs
95+
if app.Settings.Immutable { // Replace unsafe conversion funcs
10096
getString = func(b []byte) string { return string(b) }
10197
getBytes = func(s string) []byte { return []byte(s) }
10298
}
103-
app.Settings = settings[0] // Set custom settings
99+
}
100+
// Deprecated
101+
if app.Settings.Compression {
102+
log.Println("Warning: Settings.Compression is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
104103
}
105104
return app
106105
}
@@ -201,14 +200,14 @@ func (app *App) All(path string, handlers ...func(*Ctx)) *App {
201200
}
202201

203202
// WebSocket : https://fiber.wiki/application#websocket
204-
func (app *App) WebSocket(path string, handle func(*Conn)) *App {
203+
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
205204
app.registerWebSocket(http.MethodGet, path, handle)
206205
return app
207206
}
208207

209208
// Recover : https://fiber.wiki/application#recover
210209
func (app *App) Recover(handler func(*Ctx)) {
211-
log.Println("Warning: Recover(handler) is deprecated since v1.8.2, please use middleware.Recover(handler, error) instead.")
210+
log.Println("Warning: app.Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
212211
app.recover = handler
213212
}
214213

@@ -362,9 +361,8 @@ func (app *App) newServer() *fasthttp.Server {
362361
Name: app.Settings.ServerHeader,
363362
MaxRequestBodySize: app.Settings.BodyLimit,
364363
NoDefaultServerHeader: app.Settings.ServerHeader == "",
365-
366-
Logger: &disableLogger{},
367-
LogAllErrors: false,
364+
Logger: &disableLogger{},
365+
LogAllErrors: false,
368366
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
369367
if err.Error() == "body size exceeds the given limit" {
370368
ctx.Response.SetStatusCode(413)

context.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ type Ctx struct {
3131
app *App // Reference to *App
3232
route *Route // Reference to *Route
3333
index int // Index of the current stack
34-
matched bool // If the context found a match in stack
3534
method string // HTTP method
3635
path string // HTTP path
3736
values []string // Route parameter values
3837
compress bool // If the response needs to be compressed
3938
Fasthttp *fasthttp.RequestCtx // Reference to *fasthttp.RequestCtx
40-
err error // Contains error if catched
39+
Conn *Conn
40+
err error // Contains error if catched
4141
}
4242

4343
// Range struct
@@ -82,7 +82,6 @@ func releaseCtx(ctx *Ctx) {
8282
ctx.route = nil
8383
ctx.values = nil
8484
ctx.compress = false
85-
ctx.matched = false
8685
ctx.Fasthttp = nil
8786
ctx.err = nil
8887
poolCtx.Put(ctx)
@@ -322,6 +321,7 @@ func (ctx *Ctx) ClearCookie(key ...string) {
322321

323322
// Compress : https://fiber.wiki/context#compress
324323
func (ctx *Ctx) Compress(enable ...bool) {
324+
log.Println("Warning: c.Compress() is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
325325
ctx.compress = true
326326
if len(enable) > 0 {
327327
ctx.compress = enable[0]
@@ -740,7 +740,7 @@ func (ctx *Ctx) SendString(body string) {
740740

741741
// Set : https://fiber.wiki/context#set
742742
func (ctx *Ctx) Set(key string, val string) {
743-
ctx.Fasthttp.Response.Header.SetCanonical(getBytes(key), getBytes(val))
743+
ctx.Fasthttp.Response.Header.Set(key, val)
744744
}
745745

746746
// Subdomains : https://fiber.wiki/context#subdomains

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ require (
88
github.com/google/uuid v1.1.1
99
github.com/gorilla/schema v1.1.0
1010
github.com/json-iterator/go v1.1.9
11+
github.com/klauspost/compress v1.10.2 // indirect
12+
github.com/klauspost/cpuid v1.2.3 // indirect
13+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
14+
github.com/modern-go/reflect2 v1.0.1 // indirect
1115
github.com/valyala/fasthttp v1.9.0
1216
github.com/valyala/fasttemplate v1.1.0
1317
)

go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaI
1111
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
1212
github.com/fasthttp/websocket v1.4.2 h1:AU/zSiIIAuJjBMf5o+vO0syGOnEfvZRu40xIhW/3RuM=
1313
github.com/fasthttp/websocket v1.4.2/go.mod h1:smsv/h4PBEBaU0XDTY5UwJTpZv69fQ0FfcLJr21mA6Y=
14+
github.com/gofiber/fiber v1.8.2/go.mod h1:JD9ZZgxqitISS6yDcKP26BKR6Ul+z6UrZX7WlalC1sE=
15+
github.com/gofiber/recover v0.0.0-20200310140934-245859557ee6 h1:xgC7fZXV3yOQlS9liay0M9jUCDGSsPtoIuLXOEhhIFY=
16+
github.com/gofiber/recover v0.0.0-20200310140934-245859557ee6/go.mod h1:1u4FQtZ+ny7DE2R84BivzbGCYiPo0GstMvY7bJPw0Do=
1417
github.com/gofiber/template v1.0.0 h1:Vf4Fby9zUWVQyY2y69KKyRHsEYlIE+Pxb25M+jiaEL0=
1518
github.com/gofiber/template v1.0.0/go.mod h1:+bij+R0NI6urTg2jtQvPj5wb2uWMxW9eYGsAN3QhnP0=
1619
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -22,15 +25,24 @@ github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGn
2225
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
2326
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
2427
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
28+
github.com/klauspost/compress v1.10.2 h1:Znfn6hXZAHaLPNnlqUYRrBSReFHYybslgv4PTiyz6P0=
29+
github.com/klauspost/compress v1.10.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
2530
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
2631
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
32+
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
2733
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
2834
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
35+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
36+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
2937
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
3038
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
39+
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
40+
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
3141
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3242
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f h1:PgA+Olipyj258EIEYnpFFONrrCcAIWNUNoFhUfMqAGY=
3343
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f/go.mod h1:lHhJedqxCoHN+zMtwGNTXWmF0u9Jt363FYRhV6g0CdY=
44+
github.com/savsgio/gotils v0.0.0-20200308224205-e330c862e34f h1:0E9mVEuHlin0NKhic4cxMiYl7mpk1kDW+lavlU3lbjQ=
45+
github.com/savsgio/gotils v0.0.0-20200308224205-e330c862e34f/go.mod h1:lHhJedqxCoHN+zMtwGNTXWmF0u9Jt363FYRhV6g0CdY=
3446
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3547
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3648
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

group.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
125125
}
126126

127127
// WebSocket : https://fiber.wiki/application#websocket
128-
func (grp *Group) WebSocket(path string, handle func(*Conn)) *Group {
128+
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
129129
path = groupPaths(grp.prefix, path)
130130
grp.app.registerWebSocket(http.MethodGet, path, handle)
131131
return grp

middleware/basic_auth.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package middleware
22

33
import (
44
"encoding/base64"
5+
"log"
56
"strings"
67

78
"github.com/gofiber/fiber"
@@ -29,6 +30,7 @@ var BasicAuthConfigDefault = BasicAuthConfig{
2930

3031
// BasicAuth ...
3132
func BasicAuth(config ...BasicAuthConfig) func(*fiber.Ctx) {
33+
log.Println("Warning: middleware.BasicAuth() is deprecated since v1.8.3, please use github.com/gofiber/basicauth")
3234
// Init config
3335
var cfg BasicAuthConfig
3436
if len(config) > 0 {

middleware/cors.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package middleware
22

33
import (
4+
"log"
45
"net/http"
56
"strconv"
67
"strings"
@@ -41,6 +42,7 @@ var CorsConfigDefault = CORSConfig{
4142

4243
// Cors ...
4344
func Cors(config ...CORSConfig) func(*fiber.Ctx) {
45+
log.Println("Warning: middleware.Cors() is deprecated since v1.8.3, please use github.com/gofiber/cors")
4446
// Init config
4547
var cfg CORSConfig
4648
// Set config if provided

middleware/helmet.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package middleware
22

33
import (
44
"fmt"
5+
"log"
56

67
"github.com/gofiber/fiber"
78
)
@@ -51,6 +52,7 @@ var HelmetConfigDefault = HelmetConfig{
5152

5253
// Helmet ...
5354
func Helmet(config ...HelmetConfig) func(*fiber.Ctx) {
55+
log.Println("Warning: middleware.Helmet() is deprecated since v1.8.3, please use github.com/gofiber/helmet")
5456
// Init config
5557
var cfg HelmetConfig
5658
if len(config) > 0 {

middleware/limiter.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package middleware
22

33
import (
4+
"log"
45
"strconv"
56
"time"
67

@@ -48,6 +49,7 @@ var LimiterConfigDefault = LimiterConfig{
4849

4950
// Limiter ...
5051
func Limiter(config ...LimiterConfig) func(*fiber.Ctx) {
52+
log.Println("Warning: middleware.Limiter() is deprecated since v1.8.3, please use github.com/gofiber/limiter")
5153
// Init config
5254
var cfg LimiterConfig
5355
// Set config if provided

middleware/logger.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7+
"log"
78
"os"
89
"strconv"
910
"strings"
@@ -35,13 +36,14 @@ type LoggerConfig struct {
3536
// LoggerConfigDefault is the defaul Logger middleware config.
3637
var LoggerConfigDefault = LoggerConfig{
3738
Skip: nil,
38-
Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}ms\n",
39+
Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
3940
TimeFormat: "15:04:05",
4041
Output: os.Stderr,
4142
}
4243

4344
// Logger ...
4445
func Logger(config ...LoggerConfig) func(*fiber.Ctx) {
46+
log.Println("Warning: middleware.Logger() is deprecated since v1.8.3, please use github.com/gofiber/logger")
4547
// Init config
4648
var cfg LoggerConfig
4749
// Set config if provided

middleware/recover.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
// Recover ...
1111
func Recover(handle ...func(*fiber.Ctx, error)) func(*fiber.Ctx) {
12+
log.Println("Warning: middleware.Recover() is deprecated since v1.8.3, please use github.com/gofiber/recover")
1213
h := func(c *fiber.Ctx, err error) {
1314
log.Println(err)
1415
c.SendStatus(500)

middleware/request_id.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package middleware
22

33
import (
44
"fmt"
5+
"log"
56

67
"github.com/gofiber/fiber"
78
"github.com/google/uuid"
@@ -29,13 +30,14 @@ var RequestIDConfigDefault = RequestIDConfig{
2930

3031
// RequestID adds an indentifier to the request using the `X-Request-ID` header
3132
func RequestID(config ...RequestIDConfig) func(*fiber.Ctx) {
33+
log.Println("Warning: middleware.RequestID() is deprecated since v1.8.3, please use github.com/gofiber/requestid")
3234
// Init config
3335
var cfg RequestIDConfig
3436
if len(config) > 0 {
3537
cfg = config[0]
3638
}
3739
// Set config default values
38-
if cfg.Generator == nil {
40+
if cfg.Skip == nil {
3941
cfg.Skip = RequestIDConfigDefault.Skip
4042
}
4143
if cfg.Generator == nil {

0 commit comments

Comments
 (0)