✏ update spacing in code examples

pull/1018/head
Fenny 2020-11-14 03:30:33 +01:00
parent 581cac04bc
commit 51d4712b33
15 changed files with 1846 additions and 1846 deletions

278
.github/README.md vendored
View File

@ -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"))
}
```

246
.github/README_de.md vendored
View File

@ -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"))
}
```

246
.github/README_es.md vendored
View File

@ -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"))
}
```

246
.github/README_fr.md vendored
View File

@ -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"))
}
```

246
.github/README_he.md vendored
View File

@ -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"))
}
```

246
.github/README_id.md vendored
View File

@ -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"))
}
```

246
.github/README_ja.md vendored
View File

@ -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"))
}
```

246
.github/README_ko.md vendored
View File

@ -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"))
}
```

246
.github/README_nl.md vendored
View File

@ -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"))
}
```

246
.github/README_pt.md vendored
View File

@ -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"))
}
```

246
.github/README_ru.md vendored
View File

@ -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"))
}
```

246
.github/README_sa.md vendored
View File

@ -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"))
}
```

232
.github/README_tr.md vendored
View File

@ -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"))
}
```

View File

@ -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"))
}
```

View File

@ -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() {