@@ -153,12 +153,12 @@ func main() {
153153```
154154
155155### Serve static files
156-
156+ https://fiber.wiki/application#static
157157``` go
158158func main () {
159159 app := fiber.New ()
160160
161- app.Static (" /public" )
161+ app.Static (" /" , " / public" )
162162 // => http://localhost:3000/js/script.js
163163 // => http://localhost:3000/css/style.css
164164
@@ -174,7 +174,8 @@ func main() {
174174```
175175
176176### Middleware & Next
177-
177+ https://fiber.wiki/routing#middleware
178+ https://fiber.wiki/context#next
178179``` go
179180func main () {
180181 app := fiber.New ()
@@ -205,9 +206,10 @@ func main() {
205206 <summary >📚 Show more code examples</summary >
206207
207208### Template engines
209+ https://fiber.wiki/application#settings
210+ https://fiber.wiki/context#render
208211
209- Already supports:
210-
212+ Supported engines:
211213- [ html] ( https://golang.org/pkg/html/template/ )
212214- [ amber] ( https://github.com/eknkc/amber )
213215- [ handlebars] ( https://github.com/aymerick/raymond )
@@ -241,7 +243,7 @@ func main() {
241243```
242244
243245### Grouping routes into chains
244-
246+ https://fiber.wiki/application#group
245247``` go
246248func main () {
247249 app := fiber.New ()
@@ -263,8 +265,8 @@ func main() {
263265}
264266```
265267
266- ### Built-in logger
267-
268+ ### Middleware logger
269+ https://fiber.wiki/middleware#logger
268270``` go
269271import (
270272 " github.com/gofiber/fiber"
@@ -288,6 +290,7 @@ func main() {
288290```
289291
290292### Cross-Origin Resource Sharing (CORS)
293+ https://fiber.wiki/middleware#cors
291294
292295[ CORS] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS ) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.
293296
@@ -343,35 +346,40 @@ func main() {
343346```
344347
345348### JSON Response
346-
349+ https://fiber.wiki/context#json
347350``` go
351+ type User struct {
352+ Name string ` json:"name"`
353+ Age int ` json:"age"`
354+ }
355+
348356func main () {
349357 app := fiber.New ()
350358
351- type User struct {
352- Name string ` json:"name" `
353- Age int ` json:" age"`
354- }
359+ app. Get ( " /user " , func (c *fiber. Ctx ) {
360+ c. JSON (&User{ " John " , 20 })
361+ // {"name":"John", " age":20}
362+ })
355363
356- // Serialize JSON
357364 app.Get (" /json" , func (c *fiber.Ctx ) {
358- c.JSON (&User{" John" , 20 })
359- // => {"name":"John", "age":20}
365+ c.JSON (&fiber.Map {
366+ " success" : true ,
367+ " message" : " Hi John!" ,
368+ })
369+ // {"success":true, "message":"Hi John!"}
360370 })
361371
362372 app.Listen (3000 )
363373}
364374```
365375
366376### WebSocket support
367-
377+ https://fiber.wiki/application#websocket
368378``` go
369379func main () {
370380 app := fiber.New ()
371381
372- app.WebSocket (" /ws/:name" , func (c *fiber.Conn ) {
373- log.Println (c.Params (" name" ))
374-
382+ app.WebSocket (" /ws" , func (c *fiber.Conn ) {
375383 for {
376384 mt , msg , err := c.ReadMessage ()
377385 if err != nil {
@@ -389,26 +397,33 @@ func main() {
389397 }
390398 })
391399
392- // Listen on ws://localhost:3000/ws/john
400+ // Listen on ws://localhost:3000/ws
393401 app.Listen (3000 )
394402}
395403```
396404
397- ### Recover from ` panic `
398-
405+ ### Recover middleware
406+ https://fiber.wiki/middleware#recover
399407``` go
408+ package main
409+
410+ import (
411+ " github.com/gofiber/fiber"
412+ " github.com/gofiber/fiber/middleware"
413+ )
414+
400415func main () {
401416 app := fiber.New ()
402417
418+ app.Use (middleware.Recover (func (c *fiber.Ctx , err error ) {
419+ log.Println (err) // "Something went wrong!"
420+ c.SendStatus (500 ) // Internal Server Error
421+ })))
422+
403423 app.Get (" /" , func (c *fiber.Ctx ) {
404424 panic (" Something went wrong!" )
405425 })
406426
407- app.Recover (func (c *fiber.Ctx ) {
408- c.Status (500 ).Send (c.Error ())
409- // => 500 "Something went wrong!"
410- })
411-
412427 app.Listen (3000 )
413428}
414429```
@@ -437,6 +452,12 @@ If you want to say **thank you** and/or support the active development of `Fiber
437452
438453<table >
439454 <tr >
455+ <td align="center">
456+ <a href="https://github.com/gofiber/fiber">
457+ <img src="https://i.stack.imgur.com/frlIf.png" width="100px"></br>
458+ <sub><b>JustDave</b></sub>
459+ </a>
460+ </td>
440461 <td align="center">
441462 <a href="https://github.com/bihe">
442463 <img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
0 commit comments