mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-22 10:13:11 +00:00
Update examples
This commit is contained in:
parent
86ed76148a
commit
2fc60d97db
54
.github/README.md
vendored
54
.github/README.md
vendored
@ -138,14 +138,9 @@ We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues),
|
||||
|
||||
## 👀 Examples
|
||||
|
||||
Listed below are some of the common examples.
|
||||
|
||||
> If you want to see more code examples, please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our [API documentation](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -153,41 +148,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -208,10 +201,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -219,20 +209,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
54
.github/README_ar_SA.md
vendored
54
.github/README_ar_SA.md
vendored
@ -154,49 +154,44 @@ Fiber هو **مستوحى** من Express, إطار الويب الأكثر شع
|
||||
|
||||
## 👀 أمثلة
|
||||
|
||||
فيما يلي بعض الأمثلة الشائعة.
|
||||
فيما يلي بعض الأمثلة الشائعة. إذا كنت ترغب في رؤية المزيد من أمثلة التعليمات البرمجية, يرجى زيارة [Recipes repository](https://github.com/gofiber/recipes) او زيارة [API documentation](https://docs.gofiber.io).
|
||||
|
||||
> إذا كنت ترغب في رؤية المزيد من أمثلة التعليمات البرمجية, يرجى زيارة [Recipes repository](https://github.com/gofiber/recipes) او زيارة [API documentation](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
<div dir="ltr" >
|
||||
|
||||
|
||||
```go
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
@ -205,9 +200,7 @@ func main() {
|
||||
|
||||
</div>
|
||||
|
||||
### يخدم static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
<div dir="ltr">
|
||||
|
||||
@ -231,10 +224,7 @@ func main() {
|
||||
```
|
||||
</div>
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
<div dir="ltr">
|
||||
|
||||
@ -244,20 +234,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_de.md
vendored
50
.github/README_de.md
vendored
@ -138,10 +138,9 @@ Fiber ist **inspiriert** von Expressjs, dem beliebtesten Web-Framework im Intern
|
||||
|
||||
Nachfolgend sind einige der gängigen Beispiele aufgeführt. Wenn du weitere Codebeispiele sehen möchten, besuche bitte unser ["Recipes Repository"](https://github.com/gofiber/recipes) oder besuche unsere [API Dokumentation](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -149,41 +148,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -204,10 +201,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -215,20 +209,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_es.md
vendored
50
.github/README_es.md
vendored
@ -138,10 +138,9 @@ Fiber está **inspirado** en Expressjs, el framework web más popular en Interne
|
||||
|
||||
A continuación se enumeran algunos de los ejemplos comunes. Si desea ver más ejemplos de código, visite nuestro [repositorio de Recetas](https://github.com/gofiber/recipes) o nuestra [documentación de API](https://docs.gofiber.io) .
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -149,41 +148,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -204,10 +201,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -215,20 +209,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_fr.md
vendored
50
.github/README_fr.md
vendored
@ -138,10 +138,9 @@ Fiber est **inspiré** par Express, le framework web le plus populaire d'Interne
|
||||
|
||||
Ci-dessous quelques exemples courants. Si vous voulez voir plus d'exemples, rendez-vous sur notre ["Recipes repository"](https://github.com/gofiber/recipes) ou visitez notre [documentation API](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -149,41 +148,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -204,10 +201,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -215,20 +209,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
65
.github/README_he.md
vendored
65
.github/README_he.md
vendored
@ -184,23 +184,13 @@ Fiber נוצרה **בהשראת** Express, ה-web framework הפופולרית
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
להלן כמה מהדוגמאות הנפוצות.
|
||||
</div>
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
> אם ברצונכם לראות דוגמאות קוד נוספות, אנא בקרו ב[מאגר המתכונים](https://github.com/gofiber/recipes) שלנו או בקרו ב[תיעוד ה-API](https://docs.gofiber.io) שלנו.
|
||||
להלן כמה מהדוגמאות הנפוצות. אם ברצונכם לראות דוגמאות קוד נוספות, אנא בקרו ב[מאגר המתכונים](https://github.com/gofiber/recipes) שלנו או בקרו ב[תיעוד ה-API](https://docs.gofiber.io) שלנו.
|
||||
</div>
|
||||
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
### ניתוב
|
||||
</div>
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
📖 [ניתוב](https://docs.gofiber.io/#basic-routing)
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
</div>
|
||||
|
||||
```go
|
||||
@ -209,32 +199,32 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
@ -243,12 +233,7 @@ func main() {
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
### הנגשת קבצים סטטיים
|
||||
</div>
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
📖 [קבצים סטטיים](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
</div>
|
||||
|
||||
```go
|
||||
@ -272,13 +257,7 @@ func main() {
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
### Middleware & Next
|
||||
</div>
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
</div>
|
||||
|
||||
```go
|
||||
@ -287,20 +266,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_id.md
vendored
50
.github/README_id.md
vendored
@ -140,10 +140,9 @@ Kami **mendengarkan** para pengguna di [GitHub Issues](https://github.com/gofibe
|
||||
|
||||
Dibawah ini terdapat beberapa contoh penggunaan. Jika anda ingin contoh lainnya, silahkan kunjungi [Gudang resep](https://github.com/gofiber/recipes) atau kunjungi [Dokumentasi API](https://docs.gofiber.io) kami.
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -151,41 +150,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -206,10 +203,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -217,20 +211,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_ja.md
vendored
50
.github/README_ja.md
vendored
@ -141,10 +141,9 @@ Fiberは人気の高いWebフレームワークであるExpressjsに**インス
|
||||
|
||||
以下に一般的な例をいくつか示します。他のコード例をご覧になりたい場合は、 [Recipesリポジトリ](https://github.com/gofiber/recipes)または[APIドキュメント](https://docs.gofiber.io)にアクセスしてください。
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -152,41 +151,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -207,10 +204,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -218,20 +212,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_ko.md
vendored
50
.github/README_ko.md
vendored
@ -143,10 +143,9 @@ Fiber는 인터넷에서 가장 인기있는 웹 프레임워크인 Express에
|
||||
|
||||
> 더 많은 코드 예제를 보고 싶다면, [Recipes 저장소](https://github.com/gofiber/recipes) 또는 [API 문서](https://docs.gofiber.io)를 방문하세요.
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -154,41 +153,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -209,10 +206,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -220,20 +214,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_nl.md
vendored
50
.github/README_nl.md
vendored
@ -142,10 +142,9 @@ Hieronder staan enkele van de meest voorkomende voorbeelden.
|
||||
|
||||
> Bekijk ons [Recepten repository](https://github.com/gofiber/recipes) voor meer voorbeelden met code of bezoek onze [API documentatie](https://fiber.wiki).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -153,41 +152,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -208,10 +205,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -219,20 +213,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_pt.md
vendored
50
.github/README_pt.md
vendored
@ -138,10 +138,9 @@ O Fiber é **inspirado** no Express, o framework web mais popular da Internet. C
|
||||
|
||||
Listados abaixo estão alguns exemplos comuns. Se você quiser ver mais exemplos de código, visite nosso [repositório de receitas](https://github.com/gofiber/recipes) ou a [documentação da API](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -149,41 +148,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -204,10 +201,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -215,20 +209,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_ru.md
vendored
50
.github/README_ru.md
vendored
@ -140,10 +140,9 @@ Fiber **вдохновлен** Express, самым популярным веб
|
||||
|
||||
Ниже перечислены некоторые из распространенных примеров. Если вы хотите увидеть больше примеров кода, пожалуйста, посетите наш [репозиторий рецептов](https://github.com/gofiber/recipes) или [документацию по API](https://docs.gofiber.io).
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -151,41 +150,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -206,10 +203,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -217,20 +211,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
60
.github/README_tr.md
vendored
60
.github/README_tr.md
vendored
@ -138,52 +138,47 @@ Fiber internet üzerinde en popüler olan Express web çatısından **esinlenmi
|
||||
|
||||
Aşağıda yaygın örneklerden bazıları listelenmiştir. Daha fazla kod örneği görmek için, lütfen [Kod deposunu](https://github.com/gofiber/recipes) veya [API dökümantasyonunu](https://docs.gofiber.io) ziyaret ediniz.
|
||||
|
||||
### Rotalama
|
||||
|
||||
📖 [Rotalama](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// GET /john http methodunu çağır
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john http methodunu çağır
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register http methodunu çağır
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Statik Dosyaları Servis Etmek
|
||||
|
||||
📖 [Statik](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -204,31 +199,28 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Ara Katman ve İleri(Middleware & Next)
|
||||
|
||||
📖 [Ara Katman](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [İleri](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// Bütün rotalarla eşleş
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// /api ile başlayan tüm rotalarla eşleş
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register http methodunu çağır
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
50
.github/README_zh-CN.md
vendored
50
.github/README_zh-CN.md
vendored
@ -141,10 +141,9 @@ Fiber **受** Internet上最流行的Web框架Expressjs的**启发** 。我们
|
||||
|
||||
下面列出了一些常见示例。如果您想查看更多代码示例,请访问我们的[Recipes存储库](https://github.com/gofiber/recipes)或访问我们的[API文档](https://docs.gofiber.io) 。
|
||||
|
||||
### Routing
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
Listed below are some of the common examples. If you want to see more code examples , please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -152,41 +151,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### Serve static files
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -207,10 +204,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Middleware & Next
|
||||
|
||||
📖 [Middleware](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -218,20 +212,20 @@ func main() {
|
||||
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
54
.github/README_zh-TW.md
vendored
54
.github/README_zh-TW.md
vendored
@ -142,10 +142,7 @@ Fiber **受到** 網路上最流行的Web框架ExpressJS**啟發**,結合Expre
|
||||
|
||||
> 更多程式碼在[範例專案](https://github.com/gofiber/recipes)中或直接看[API文件](https://docs.gofiber.io)。
|
||||
|
||||
### 路由
|
||||
|
||||
📖 [Routing](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
#### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -153,41 +150,39 @@ func main() {
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Hello %s!", c.Params("name"))
|
||||
// => Hello john!
|
||||
c.Send("Hello, ", c.Params("name"), " 👋!")
|
||||
// => Hello john 👋!
|
||||
})
|
||||
|
||||
// GET /john
|
||||
app.Get("/:name/:age?", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
|
||||
// => Name: john, Age:
|
||||
// GET /john/75
|
||||
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) {
|
||||
c.Send(c.Params("name"), " is ", c.Params("age"), " years old 👴")
|
||||
// => john is 75 years old 👴
|
||||
})
|
||||
|
||||
// GET /plantae/prunus.persica
|
||||
app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
|
||||
fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
|
||||
// => Genius: prunus, Species: persica
|
||||
// GET /dictionary.txt
|
||||
app.Get("/:file.:ext", func(c *fiber.Ctx) {
|
||||
c.Send("📃 ", c.Params("file"), ".", c.Params("ext"))
|
||||
// => 📃 dictionary.txt
|
||||
})
|
||||
|
||||
// GET /flights/LAX-SFO
|
||||
app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
|
||||
fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
|
||||
// => From: LAX, To: SFO
|
||||
c.Send("✈ From ", c.Params("from"), ", To: ", c.Params("to"))
|
||||
// => ✈ From: LAX, To: SFO
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/*", func(c *fiber.Ctx) {
|
||||
fmt.Printf("/api/%s", c.Params("*"))
|
||||
// => /api/register
|
||||
c.Send("✋ ", c.Params("*"))
|
||||
// => ✋ /api/register
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
}
|
||||
```
|
||||
|
||||
### 靜態檔案
|
||||
|
||||
📖 [Static](https://docs.gofiber.io/application#static)
|
||||
#### 📖 [**Serving Static Files**](https://docs.gofiber.io/application#static)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
@ -208,31 +203,28 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### 中介器和下一步
|
||||
|
||||
📖 [中介器](https://docs.gofiber.io/routing#middleware)
|
||||
📖 [Next](https://docs.gofiber.io/context#next)
|
||||
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/context#next)
|
||||
|
||||
```go
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// 符合任何路徑
|
||||
// Match any route
|
||||
app.Use(func(c *fiber.Ctx) {
|
||||
fmt.Println("First middleware")
|
||||
fmt.Println("🥇 First handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// 符合以/api開頭的路徑
|
||||
// Match all routes starting with /api
|
||||
app.Use("/api", func(c *fiber.Ctx) {
|
||||
fmt.Println("Second middleware")
|
||||
fmt.Println("🥈 Second handler")
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// GET /api/register
|
||||
app.Get("/api/list", func(c *fiber.Ctx) {
|
||||
fmt.Println("Last middleware")
|
||||
c.Send("Hello, World!")
|
||||
fmt.Println("🥉 Last handler")
|
||||
c.Send("Hello, World 👋!")
|
||||
})
|
||||
|
||||
app.Listen(3000)
|
||||
|
Loading…
x
Reference in New Issue
Block a user