Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package fiber
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"log"
Expand All @@ -26,7 +25,7 @@ import (
)

// Version of Fiber
const Version = "1.8.2"
const Version = "1.8.3"

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

func init() {
flag.Bool("prefork", false, "Use prefork")
flag.Bool("child", false, "Is a child process")
}

// New : https://fiber.wiki/application#new
func New(settings ...*Settings) *App {
var prefork, child bool
Expand All @@ -90,17 +85,21 @@ func New(settings ...*Settings) *App {
}
// If settings exist, set some defaults
if len(settings) > 0 {
if !settings[0].Prefork { // Default to -prefork flag if false
settings[0].Prefork = prefork
app.Settings = settings[0] // Set custom settings
if !app.Settings.Prefork { // Default to -prefork flag if false
app.Settings.Prefork = prefork
}
if settings[0].BodyLimit == 0 { // Default MaxRequestBodySize
settings[0].BodyLimit = 4 * 1024 * 1024
if app.Settings.BodyLimit == 0 { // Default MaxRequestBodySize
app.Settings.BodyLimit = 4 * 1024 * 1024
}
if settings[0].Immutable { // Replace unsafe conversion funcs
if app.Settings.Immutable { // Replace unsafe conversion funcs
getString = func(b []byte) string { return string(b) }
getBytes = func(s string) []byte { return []byte(s) }
}
app.Settings = settings[0] // Set custom settings
}
// Deprecated
if app.Settings.Compression {
log.Println("Warning: Settings.Compression is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
}
return app
}
Expand Down Expand Up @@ -201,14 +200,14 @@ func (app *App) All(path string, handlers ...func(*Ctx)) *App {
}

// WebSocket : https://fiber.wiki/application#websocket
func (app *App) WebSocket(path string, handle func(*Conn)) *App {
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
app.registerWebSocket(http.MethodGet, path, handle)
return app
}

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

Expand Down Expand Up @@ -362,9 +361,8 @@ func (app *App) newServer() *fasthttp.Server {
Name: app.Settings.ServerHeader,
MaxRequestBodySize: app.Settings.BodyLimit,
NoDefaultServerHeader: app.Settings.ServerHeader == "",

Logger: &disableLogger{},
LogAllErrors: false,
Logger: &disableLogger{},
LogAllErrors: false,
ErrorHandler: func(ctx *fasthttp.RequestCtx, err error) {
if err.Error() == "body size exceeds the given limit" {
ctx.Response.SetStatusCode(413)
Expand Down
9 changes: 5 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type Ctx struct {
app *App // Reference to *App
route *Route // Reference to *Route
index int // Index of the current stack
matched bool // If the context found a match in stack
method string // HTTP method
path string // HTTP path
values []string // Route parameter values
compress bool // If the response needs to be compressed
Fasthttp *fasthttp.RequestCtx // Reference to *fasthttp.RequestCtx
err error // Contains error if catched
Conn *Conn
err error // Contains error if catched
}

// Range struct
Expand Down Expand Up @@ -82,14 +82,14 @@ func releaseCtx(ctx *Ctx) {
ctx.route = nil
ctx.values = nil
ctx.compress = false
ctx.matched = false
ctx.Fasthttp = nil
ctx.err = nil
poolCtx.Put(ctx)
}

// Conn https://godoc.org/github.com/gorilla/websocket#pkg-index
type Conn struct {
locals map[string]interface{}
*websocket.Conn
}

Expand Down Expand Up @@ -322,6 +322,7 @@ func (ctx *Ctx) ClearCookie(key ...string) {

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

// Set : https://fiber.wiki/context#set
func (ctx *Ctx) Set(key string, val string) {
ctx.Fasthttp.Response.Header.SetCanonical(getBytes(key), getBytes(val))
ctx.Fasthttp.Response.Header.Set(key, val)
}

// Subdomains : https://fiber.wiki/context#subdomains
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ require (
github.com/google/uuid v1.1.1
github.com/gorilla/schema v1.1.0
github.com/json-iterator/go v1.1.9
github.com/klauspost/compress v1.10.2 // indirect
github.com/klauspost/cpuid v1.2.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/valyala/fasthttp v1.9.0
github.com/valyala/fasttemplate v1.1.0
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaI
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/fasthttp/websocket v1.4.2 h1:AU/zSiIIAuJjBMf5o+vO0syGOnEfvZRu40xIhW/3RuM=
github.com/fasthttp/websocket v1.4.2/go.mod h1:smsv/h4PBEBaU0XDTY5UwJTpZv69fQ0FfcLJr21mA6Y=
github.com/gofiber/fiber v1.8.2/go.mod h1:JD9ZZgxqitISS6yDcKP26BKR6Ul+z6UrZX7WlalC1sE=
github.com/gofiber/recover v0.0.0-20200310140934-245859557ee6 h1:xgC7fZXV3yOQlS9liay0M9jUCDGSsPtoIuLXOEhhIFY=
github.com/gofiber/recover v0.0.0-20200310140934-245859557ee6/go.mod h1:1u4FQtZ+ny7DE2R84BivzbGCYiPo0GstMvY7bJPw0Do=
github.com/gofiber/template v1.0.0 h1:Vf4Fby9zUWVQyY2y69KKyRHsEYlIE+Pxb25M+jiaEL0=
github.com/gofiber/template v1.0.0/go.mod h1:+bij+R0NI6urTg2jtQvPj5wb2uWMxW9eYGsAN3QhnP0=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand All @@ -22,15 +25,24 @@ github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGn
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.2 h1:Znfn6hXZAHaLPNnlqUYRrBSReFHYybslgv4PTiyz6P0=
github.com/klauspost/compress v1.10.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f h1:PgA+Olipyj258EIEYnpFFONrrCcAIWNUNoFhUfMqAGY=
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f/go.mod h1:lHhJedqxCoHN+zMtwGNTXWmF0u9Jt363FYRhV6g0CdY=
github.com/savsgio/gotils v0.0.0-20200308224205-e330c862e34f h1:0E9mVEuHlin0NKhic4cxMiYl7mpk1kDW+lavlU3lbjQ=
github.com/savsgio/gotils v0.0.0-20200308224205-e330c862e34f/go.mod h1:lHhJedqxCoHN+zMtwGNTXWmF0u9Jt363FYRhV6g0CdY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
2 changes: 1 addition & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
}

// WebSocket : https://fiber.wiki/application#websocket
func (grp *Group) WebSocket(path string, handle func(*Conn)) *Group {
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
path = groupPaths(grp.prefix, path)
grp.app.registerWebSocket(http.MethodGet, path, handle)
return grp
Expand Down
2 changes: 2 additions & 0 deletions middleware/basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"encoding/base64"
"log"
"strings"

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

// BasicAuth ...
func BasicAuth(config ...BasicAuthConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.BasicAuth() is deprecated since v1.8.3, please use github.com/gofiber/basicauth")
// Init config
var cfg BasicAuthConfig
if len(config) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions middleware/cors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"log"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -41,6 +42,7 @@ var CorsConfigDefault = CORSConfig{

// Cors ...
func Cors(config ...CORSConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.Cors() is deprecated since v1.8.3, please use github.com/gofiber/cors")
// Init config
var cfg CORSConfig
// Set config if provided
Expand Down
2 changes: 2 additions & 0 deletions middleware/helmet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"fmt"
"log"

"github.com/gofiber/fiber"
)
Expand Down Expand Up @@ -51,6 +52,7 @@ var HelmetConfigDefault = HelmetConfig{

// Helmet ...
func Helmet(config ...HelmetConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.Helmet() is deprecated since v1.8.3, please use github.com/gofiber/helmet")
// Init config
var cfg HelmetConfig
if len(config) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions middleware/limiter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"log"
"strconv"
"time"

Expand Down Expand Up @@ -48,6 +49,7 @@ var LimiterConfigDefault = LimiterConfig{

// Limiter ...
func Limiter(config ...LimiterConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.Limiter() is deprecated since v1.8.3, please use github.com/gofiber/limiter")
// Init config
var cfg LimiterConfig
// Set config if provided
Expand Down
4 changes: 3 additions & 1 deletion middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -35,13 +36,14 @@ type LoggerConfig struct {
// LoggerConfigDefault is the defaul Logger middleware config.
var LoggerConfigDefault = LoggerConfig{
Skip: nil,
Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}ms\n",
Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
TimeFormat: "15:04:05",
Output: os.Stderr,
}

// Logger ...
func Logger(config ...LoggerConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.Logger() is deprecated since v1.8.3, please use github.com/gofiber/logger")
// Init config
var cfg LoggerConfig
// Set config if provided
Expand Down
1 change: 1 addition & 0 deletions middleware/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// Recover ...
func Recover(handle ...func(*fiber.Ctx, error)) func(*fiber.Ctx) {
log.Println("Warning: middleware.Recover() is deprecated since v1.8.3, please use github.com/gofiber/recover")
h := func(c *fiber.Ctx, err error) {
log.Println(err)
c.SendStatus(500)
Expand Down
4 changes: 3 additions & 1 deletion middleware/request_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"fmt"
"log"

"github.com/gofiber/fiber"
"github.com/google/uuid"
Expand Down Expand Up @@ -29,13 +30,14 @@ var RequestIDConfigDefault = RequestIDConfig{

// RequestID adds an indentifier to the request using the `X-Request-ID` header
func RequestID(config ...RequestIDConfig) func(*fiber.Ctx) {
log.Println("Warning: middleware.RequestID() is deprecated since v1.8.3, please use github.com/gofiber/requestid")
// Init config
var cfg RequestIDConfig
if len(config) > 0 {
cfg = config[0]
}
// Set config default values
if cfg.Generator == nil {
if cfg.Skip == nil {
cfg.Skip = RequestIDConfigDefault.Skip
}
if cfg.Generator == nil {
Expand Down
Loading