From 51d4712b33fcf0bd4fe6bb697ae110fe0925fc67 Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Sat, 14 Nov 2020 03:30:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=20update=20spacing=20in=20code=20exam?= =?UTF-8?q?ples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/README.md | 278 ++++++++++++++++++++-------------------- .github/README_de.md | 246 +++++++++++++++++------------------ .github/README_es.md | 246 +++++++++++++++++------------------ .github/README_fr.md | 246 +++++++++++++++++------------------ .github/README_he.md | 246 +++++++++++++++++------------------ .github/README_id.md | 246 +++++++++++++++++------------------ .github/README_ja.md | 246 +++++++++++++++++------------------ .github/README_ko.md | 246 +++++++++++++++++------------------ .github/README_nl.md | 246 +++++++++++++++++------------------ .github/README_pt.md | 246 +++++++++++++++++------------------ .github/README_ru.md | 246 +++++++++++++++++------------------ .github/README_sa.md | 246 +++++++++++++++++------------------ .github/README_tr.md | 232 ++++++++++++++++----------------- .github/README_zh-CN.md | 246 +++++++++++++++++------------------ .github/README_zh-TW.md | 230 ++++++++++++++++----------------- 15 files changed, 1846 insertions(+), 1846 deletions(-) diff --git a/.github/README.md b/.github/README.md index 8eab20fd..490ed182 100644 --- a/.github/README.md +++ b/.github/README.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -144,39 +144,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -185,20 +185,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -207,27 +207,27 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - // Match any route - app.Use(func(c *fiber.Ctx) error { - fmt.Println("πŸ₯‡ First handler") - return c.Next() - }) + // Match any route + app.Use(func(c *fiber.Ctx) error { + fmt.Println("πŸ₯‡ First handler") + return c.Next() + }) - // Match all routes starting with /api - app.Use("/api", func(c *fiber.Ctx) error { - fmt.Println("πŸ₯ˆ Second handler") - return c.Next() - }) + // Match all routes starting with /api + app.Use("/api", func(c *fiber.Ctx) error { + fmt.Println("πŸ₯ˆ Second handler") + return c.Next() + }) - // GET /api/register - app.Get("/api/list", func(c *fiber.Ctx) error { - fmt.Println("πŸ₯‰ Last handler") - return c.SendString("Hello, World πŸ‘‹!") - }) + // GET /api/register + app.Get("/api/list", func(c *fiber.Ctx) error { + fmt.Println("πŸ₯‰ Last handler") + return c.SendString("Hello, World πŸ‘‹!") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -251,25 +251,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -279,31 +279,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -316,20 +316,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -339,20 +339,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -368,25 +368,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -396,27 +396,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -460,20 +460,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_de.md b/.github/README_de.md index 877a4087..1f878c6f 100644 --- a/.github/README_de.md +++ b/.github/README_de.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -144,39 +144,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -185,20 +185,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -251,25 +251,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -279,31 +279,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -316,20 +316,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -339,20 +339,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -368,25 +368,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -396,27 +396,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -427,7 +427,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -460,20 +460,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_es.md b/.github/README_es.md index a178170d..d3508b28 100644 --- a/.github/README_es.md +++ b/.github/README_es.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -141,39 +141,39 @@ A continuaciΓ³n se enumeran algunos de los ejemplos comunes. Si desea ver mΓ‘s e ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -182,20 +182,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -248,25 +248,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -276,31 +276,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -313,20 +313,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -336,20 +336,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -365,25 +365,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -393,27 +393,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -424,7 +424,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -457,20 +457,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_fr.md b/.github/README_fr.md index 3cf5668d..61456116 100644 --- a/.github/README_fr.md +++ b/.github/README_fr.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -144,39 +144,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -185,20 +185,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -251,25 +251,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -279,31 +279,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -316,20 +316,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -339,20 +339,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -368,25 +368,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -396,27 +396,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -427,7 +427,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -460,20 +460,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_he.md b/.github/README_he.md index 297324af..0cf39f2e 100644 --- a/.github/README_he.md +++ b/.github/README_he.md @@ -93,13 +93,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -197,39 +197,39 @@ Fiber Χ Χ•Χ¦Χ¨Χ” **בהשראΧͺ** Express, Χ”-web framework Χ”Χ€Χ•Χ€Χ•ΧœΧ¨Χ™Χͺ ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -242,20 +242,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -315,25 +315,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -347,31 +347,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -388,20 +388,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -415,20 +415,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -452,25 +452,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -484,27 +484,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -519,7 +519,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -556,20 +556,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_id.md b/.github/README_id.md index 0ffa1526..68b8ae46 100644 --- a/.github/README_id.md +++ b/.github/README_id.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -144,39 +144,39 @@ Dibawah ini terdapat beberapa contoh penggunaan. Jika anda ingin melihat contoh ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -185,20 +185,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -251,25 +251,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -279,31 +279,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -316,20 +316,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -339,20 +339,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -368,25 +368,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -396,27 +396,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -427,7 +427,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -460,20 +460,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_ja.md b/.github/README_ja.md index 6e7b8db1..b1e2c68c 100644 --- a/.github/README_ja.md +++ b/.github/README_ja.md @@ -85,13 +85,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -148,39 +148,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -189,20 +189,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -255,25 +255,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -283,31 +283,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -320,20 +320,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -343,20 +343,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -372,25 +372,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -400,27 +400,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -431,7 +431,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -464,20 +464,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_ko.md b/.github/README_ko.md index 97cd87da..a552b268 100644 --- a/.github/README_ko.md +++ b/.github/README_ko.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -148,39 +148,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -189,20 +189,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -255,25 +255,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -283,31 +283,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -320,20 +320,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -343,20 +343,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -372,25 +372,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -400,27 +400,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -431,7 +431,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -464,20 +464,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_nl.md b/.github/README_nl.md index 8c3a9c65..b9af8d45 100644 --- a/.github/README_nl.md +++ b/.github/README_nl.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -148,39 +148,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -189,20 +189,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -255,25 +255,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -283,31 +283,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -320,20 +320,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -343,20 +343,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -372,25 +372,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -400,27 +400,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -431,7 +431,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -464,20 +464,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_pt.md b/.github/README_pt.md index e50d3fe1..eeacb73a 100644 --- a/.github/README_pt.md +++ b/.github/README_pt.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -144,39 +144,39 @@ a [documentação da API](https://docs.gofiber.io). ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -185,20 +185,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -249,25 +249,25 @@ Se vocΓͺ quiser uma execução parcial ou usar uma engine diferente como [amber] package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -277,31 +277,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -314,20 +314,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -337,20 +337,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -366,25 +366,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -394,27 +394,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -425,7 +425,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -458,20 +458,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_ru.md b/.github/README_ru.md index e5704c93..99e18c24 100644 --- a/.github/README_ru.md +++ b/.github/README_ru.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -146,39 +146,39 @@ Listed below are some of the common examples. If you want to see more code examp ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -187,20 +187,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -253,25 +253,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -281,31 +281,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -318,20 +318,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -341,20 +341,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -370,25 +370,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -398,27 +398,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -429,7 +429,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -462,20 +462,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_sa.md b/.github/README_sa.md index a7cb325c..7cb8c3b5 100644 --- a/.github/README_sa.md +++ b/.github/README_sa.md @@ -88,13 +88,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -155,39 +155,39 @@ Fiber Ω‡Ωˆ **Ω…Ψ³ΨͺΩˆΨ­Ω‰** Ω…Ω† Express, Ψ₯Ψ·Ψ§Ψ± Ψ§Ω„ΩˆΩŠΨ¨ Ψ§Ω„Ψ£ΩƒΨ«Ψ± Ψ΄ΨΉ ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -200,20 +200,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -274,25 +274,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -306,31 +306,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -347,20 +347,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -374,20 +374,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -411,25 +411,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -443,27 +443,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -478,7 +478,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -515,20 +515,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_tr.md b/.github/README_tr.md index 0a772366..85050ef6 100644 --- a/.github/README_tr.md +++ b/.github/README_tr.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -142,39 +142,39 @@ Aşağıda yaygΔ±n ΓΆrneklerden bazΔ±larΔ± listelenmiştir. Daha fazla kod ΓΆrne ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -183,20 +183,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -249,25 +249,25 @@ Checkout our [Template](https://github.com/gofiber/template) package that suppor package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -277,31 +277,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -336,20 +336,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -365,25 +365,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -393,27 +393,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -424,7 +424,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -457,20 +457,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_zh-CN.md b/.github/README_zh-CN.md index 6e64bd55..667c4a9c 100644 --- a/.github/README_zh-CN.md +++ b/.github/README_zh-CN.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -143,39 +143,39 @@ go get -u github.com/gofiber/fiber/v2 ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -184,20 +184,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -250,25 +250,25 @@ func main() { package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -278,31 +278,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -315,20 +315,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -338,20 +338,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -367,25 +367,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -395,27 +395,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -426,7 +426,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() { @@ -459,20 +459,20 @@ func main() { ```go import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/recover" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(recover.New()) + app.Use(recover.New()) - app.Get("/", func(c *fiber.Ctx) error { - panic("normally this would crash your app") - }) + app.Get("/", func(c *fiber.Ctx) error { + panic("normally this would crash your app") + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` diff --git a/.github/README_zh-TW.md b/.github/README_zh-TW.md index 5d8c86ae..d9c0e7d0 100644 --- a/.github/README_zh-TW.md +++ b/.github/README_zh-TW.md @@ -84,13 +84,13 @@ package main import "github.com/gofiber/fiber/v2" func main() { - app := fiber.New() + app := fiber.New() - app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World πŸ‘‹!") - }) + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World πŸ‘‹!") + }) - app.Listen(":3000") + app.Listen(":3000") } ``` @@ -146,39 +146,39 @@ Fiber **ε—εˆ°** ηΆ²θ·―δΈŠζœ€ζ΅θ‘Œηš„ Web ζ‘†ζžΆ ExpressJS**ε•Ÿη™Ό**,硐合 E ```go func main() { - app := fiber.New() + app := fiber.New() - // GET /john - app.Get("/:name", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) - return c.SendString(msg) // => Hello john πŸ‘‹! - }) + // GET /john + app.Get("/:name", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name")) + return c.SendString(msg) // => Hello john πŸ‘‹! + }) - // GET /john/75 - app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) - return c.SendString(msg) // => πŸ‘΄ john is 75 years old - }) + // GET /john/75 + app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age")) + return c.SendString(msg) // => πŸ‘΄ john is 75 years old + }) - // GET /dictionary.txt - app.Get("/:file.:ext", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) - return c.SendString(msg) // => πŸ“ƒ dictionary.txt - }) + // GET /dictionary.txt + app.Get("/:file.:ext", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext")) + return c.SendString(msg) // => πŸ“ƒ dictionary.txt + }) - // GET /flights/LAX-SFO - app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) - return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO - }) + // GET /flights/LAX-SFO + app.Get("/flights/:from-:to", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to")) + return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO + }) - // GET /api/register - app.Get("/api/*", func(c *fiber.Ctx) error { - msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) - return c.SendString(msg) // => βœ‹ register - }) + // GET /api/register + app.Get("/api/*", func(c *fiber.Ctx) error { + msg := fmt.Sprintf("βœ‹ %s", c.Params("*")) + return c.SendString(msg) // => βœ‹ register + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -187,20 +187,20 @@ func main() { ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") - // => http://localhost:3000/js/script.js - // => http://localhost:3000/css/style.css + app.Static("/", "./public") + // => http://localhost:3000/js/script.js + // => http://localhost:3000/css/style.css - app.Static("/prefix", "./public") - // => http://localhost:3000/prefix/js/script.js - // => http://localhost:3000/prefix/css/style.css + app.Static("/prefix", "./public") + // => http://localhost:3000/prefix/js/script.js + // => http://localhost:3000/prefix/css/style.css - app.Static("*", "./public/index.html") - // => http://localhost:3000/any/path/shows/index/html + app.Static("*", "./public/index.html") + // => http://localhost:3000/any/path/shows/index/html - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -251,25 +251,25 @@ func main() { package main import ( - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/pug" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/pug" ) func main() { - // You can setup Views engine before initiation app: - app := fiber.New(fiber.Config{ - Views: pug.New("./views", ".pug"), - }) + // You can setup Views engine before initiation app: + app := fiber.New(fiber.Config{ + Views: pug.New("./views", ".pug"), + }) - // And now, you can call template `./views/home.pug` like this: - app.Get("/", func(c *fiber.Ctx) error { - return c.Render("home", fiber.Map{ - "title": "Homepage", - "year": 1999, - }) - }) + // And now, you can call template `./views/home.pug` like this: + app.Get("/", func(c *fiber.Ctx) error { + return c.Render("home", fiber.Map{ + "title": "Homepage", + "year": 1999, + }) + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -280,31 +280,31 @@ func main() { ```go func middleware(c *fiber.Ctx) error { - fmt.Println("Don't mind me!") - return c.Next() + fmt.Println("Don't mind me!") + return c.Next() } func handler(c *fiber.Ctx) error { - return c.SendString(c.Path()) + return c.SendString(c.Path()) } func main() { - app := fiber.New() + app := fiber.New() - // Root API route - api := app.Group("/api", middleware) // /api + // Root API route + api := app.Group("/api", middleware) // /api - // API v1 routes - v1 := api.Group("/v1", middleware) // /api/v1 - v1.Get("/list", handler) // /api/v1/list - v1.Get("/user", handler) // /api/v1/user + // API v1 routes + v1 := api.Group("/v1", middleware) // /api/v1 + v1.Get("/list", handler) // /api/v1/list + v1.Get("/user", handler) // /api/v1/user - // API v2 routes - v2 := api.Group("/v2", middleware) // /api/v2 - v2.Get("/list", handler) // /api/v2/list - v2.Get("/user", handler) // /api/v2/user + // API v2 routes + v2 := api.Group("/v2", middleware) // /api/v2 + v2.Get("/list", handler) // /api/v2/list + v2.Get("/user", handler) // /api/v2/user - // ... + // ... } ``` @@ -317,20 +317,20 @@ func main() { package main import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(logger.New()) + app.Use(logger.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -340,20 +340,20 @@ func main() { ```go import ( - "log" + "log" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { - app := fiber.New() + app := fiber.New() - app.Use(cors.New()) + app.Use(cors.New()) - // ... + // ... - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -369,25 +369,25 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ```go func main() { - app := fiber.New() + app := fiber.New() - app.Static("/", "./public") + app.Static("/", "./public") - app.Get("/demo", func(c *fiber.Ctx) error { - return c.SendString("This is a demo!") - }) + app.Get("/demo", func(c *fiber.Ctx) error { + return c.SendString("This is a demo!") + }) - app.Post("/register", func(c *fiber.Ctx) error { - return c.SendString("Welcome!") - }) + app.Post("/register", func(c *fiber.Ctx) error { + return c.SendString("Welcome!") + }) - // Last middleware to match anything - app.Use(func(c *fiber.Ctx) error { - return c.SendStatus(404) - // => 404 "Not Found" - }) + // Last middleware to match anything + app.Use(func(c *fiber.Ctx) error { + return c.SendStatus(404) + // => 404 "Not Found" + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -397,27 +397,27 @@ func main() { ```go type User struct { - Name string `json:"name"` - Age int `json:"age"` + Name string `json:"name"` + Age int `json:"age"` } func main() { - app := fiber.New() + app := fiber.New() - app.Get("/user", func(c *fiber.Ctx) error { - return c.JSON(&User{"John", 20}) - // => {"name":"John", "age":20} - }) + app.Get("/user", func(c *fiber.Ctx) error { + return c.JSON(&User{"John", 20}) + // => {"name":"John", "age":20} + }) - app.Get("/json", func(c *fiber.Ctx) error { - return c.JSON(fiber.Map{ - "success": true, - "message": "Hi John!", - }) - // => {"success":true, "message":"Hi John!"} - }) + app.Get("/json", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", + }) + // => {"success":true, "message":"Hi John!"} + }) - log.Fatal(app.Listen(":3000")) + log.Fatal(app.Listen(":3000")) } ``` @@ -428,7 +428,7 @@ func main() { ```go import ( "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket" + "github.com/gofiber/fiber/v2/middleware/websocket" ) func main() {