Fiber v2.0.0 Release Notes
Release Date: 2020-02-21 // about 4 years ago-
Fiber v2 #92
โ Add multiple handlers inside routes & groups.func main() { // ... app.Get("/", middleware(), middleware(), handler()) }
Pass optional settings in the app initiation.
func main() { app := fiber.New(&fiber.Settings{ Prefork: true, CaseSensitive: true, StrictRouting: true, ServerHeader: "Go", // etc... }) }
Chain groups
func main() { app := fiber.New() api := app.Group("/api", cors()) // /apiv1 := api.Group("/v1", mysql()) // /api/v1 v1.Get("/list", handler) // /api/v1/list v1.Get("/user", handler) // /api/v1/userv2 := api.Group("/v2", mongodb()) // /api/v2 v2.Get("/list", handler) // /api/v2/list v2.Get("/user", handler) // /api/v2/user app.Listen(3000) }
Recover from panics
func main() { app := fiber.New() app.Get("/", func(c \*fiber.Ctx) { panic("Something went wrong!") }) app.Recover(func(c \*fiber.Ctx) { c.Status(500).Send(c.Error()) // =\> 500 "Something went wrong!" }) app.Listen(3000) }
๐ Websocket support using gorilla *Conn
func main() { app := fiber.New() app.WebSocket("/ws/:name", func(c \*fiber.Conn) { log.Println(c.Params("name")) for { mt, msg, err := c.ReadMessage() if err != nil { log.Println("read:", err) break } log.Printf("recv: %s", msg) err = c.WriteMessage(mt, msg) if err != nil { log.Println("write:", err) break } } }) // ws://localhost:3000/ws/john app.Listen(3000) }
๐ New features
๐ ctx.BodyParser / https://fiber.wiki/context#bodyparser
ctx.Error / https://fiber.wiki/context#error
ctx.Next / https://fiber.wiki/context#next
ctx.Render / https://fiber.wiki/context#renderapp.New / https://fiber.wiki/application#settings
app.Recover / https://fiber.wiki/application#recover
app.Group / https://fiber.wiki/application#group
๐ฑ ๐ app.WebSocket / https://fiber.wiki/application#websocket
app.Settings / https://fiber.wiki/application#settings๐ Deprecated
ctx.BasicAuth
ctx.Json
ctx.JsonBytes
ctx.JSONBytes
ctx.JsonString
ctx.JSONString
ctx.Xml
ctx.XMLapp.Prefork
app.Engine
app.Banner