1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 15:23:58 +00:00

Merge branch 'master' into master

This commit is contained in:
Joey 2020-11-12 20:31:28 +01:00 committed by GitHub
commit d1098d7057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 59 additions and 38 deletions

2
.github/README.md vendored
View File

@ -528,7 +528,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [ansrivas/fiberprometheus](https://github.com/ansrivas/fiberprometheus)
- [LdDl/fiber-long-poll](https://github.com/LdDl/fiber-long-poll)

View File

@ -524,7 +524,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -104,10 +104,9 @@ Estas pruebas son realizadas por [TechEmpower](https://www.techempower.com/bench
</p>
## ⚙️ Instalación
Asegúrese de tener instalado Go ([download](https://golang.org/dl/)). Version `1.14` o superior.
Make sure you have Go installed ([download](https://golang.org/dl/)). Version `1.14` or higher is required.
Initialize your project by creating a folder and then running `go mod init github.com/your/repo` ([learn more](https://blog.golang.org/using-go-modules)) inside the folder. Then install Fiber with the [`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) command:
Arranque su proyecto creando una nueva carpeta y ejecutando `go mod init github.com/your/repo` ([mas información](https://blog.golang.org/using-go-modules)) dentro de la misma carpeta. Después instale Fiber mediante el comando [`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them):
```bash
go get -u github.com/gofiber/fiber/v2
@ -138,8 +137,6 @@ 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) .
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
@ -524,7 +521,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -524,7 +524,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -654,7 +654,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -524,7 +524,7 @@ Berikut adalah kumpulan _middlewares_ yang dibuat oleh komunitas Fiber, silahkan
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -528,7 +528,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -528,7 +528,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -528,7 +528,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -522,7 +522,7 @@ Esta é uma lista de middlewares criados pela comunidade do Fiber, se quiser ter
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -526,7 +526,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -580,7 +580,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -521,7 +521,7 @@ This is a list of middlewares that are created by the Fiber community, please cr
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -104,10 +104,9 @@ func main() {
</p>
## ⚙️ 安装
确保已安装 ([下载](https://golang.org/dl/)) `1.14` 或更高版本的 Go。
Make sure you have Go installed ([download](https://golang.org/dl/)). Version `1.14` or higher is required.
Initialize your project by creating a folder and then running `go mod init github.com/your/repo` ([learn more](https://blog.golang.org/using-go-modules)) inside the folder. Then install Fiber with the [`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) command:
通过创建文件夹并在文件夹内运行 `go mod init github.com/your/repo` ([了解更多](https://blog.golang.org/using-go-modules)) 来初始化项目,然后使用 [`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) 命令安装 Fiber
```bash
go get -u github.com/gofiber/fiber/v2
@ -524,7 +523,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -524,7 +524,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [itsursujit/fiber-boilerplate](https://github.com/itsursujit/fiber-boilerplate)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)

View File

@ -562,7 +562,7 @@ func Test_App_Static_Direct(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get("Content-Type"))
utils.AssertEqual(t, "", resp.Header.Get(HeaderCacheControl), "CacheControl Control")
body, err = ioutil.ReadAll(resp.Body)
@ -600,7 +600,7 @@ func Test_App_Static_Group(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, "123", resp.Header.Get("Test-Header"))
grp = app.Group("/v2")
@ -611,7 +611,7 @@ func Test_App_Static_Group(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
}
@ -625,7 +625,7 @@ func Test_App_Static_Wildcard(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
@ -643,7 +643,7 @@ func Test_App_Static_Prefix_Wildcard(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
app.Static("/my/nameisjohn*", "./.github/FUNDING.yml")
@ -651,7 +651,7 @@ func Test_App_Static_Prefix_Wildcard(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
@ -667,7 +667,7 @@ func Test_App_Static_Prefix(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
app.Static("/prefix", "./.github/workflows")
@ -676,7 +676,7 @@ func Test_App_Static_Prefix(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
app.Static("/single", "./.github/workflows/test.yml")
@ -685,7 +685,7 @@ func Test_App_Static_Prefix(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
}
func Test_App_Static_Trailing_Slash(t *testing.T) {
@ -697,7 +697,7 @@ func Test_App_Static_Trailing_Slash(t *testing.T) {
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 404, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "")
utils.AssertEqual(t, "text/plain; charset=utf-8", resp.Header.Get(HeaderContentType))
utils.AssertEqual(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
}
// go test -run Test_App_Mixed_Routes_WithSameLen

View File

@ -13,8 +13,8 @@ Logger middleware for [Fiber](https://github.com/gofiber/fiber) that logs HTTP r
func New(config ...Config) fiber.Handler
```
### Examples
Import the middleware package that is part of the Fiber web framework
## Examples
First ensure the appropriate packages are imported
```go
import (
"github.com/gofiber/fiber/v2"
@ -22,17 +22,42 @@ import (
)
```
After you initiate your Fiber app, you can use the following possibilities:
#### **Initialization / Default Config**
```go
// Default middleware config
app.Use(logger.New())
```
// Or extend your config for customization
#### **Logging Request ID**
```go
app.Use(requestid.New())
app.Use(logger.New(logger.Config{
// For more options, see the Config section
Format: "${pid} ${locals:requestid} ${status} - ${method} ${path}\n",
}))
```
#### **Changing TimeZone & TimeFormat**
```go
app.Use(logger.New(logger.Config{
Format: "${pid} ${status} - ${method} ${path}\n",
TimeFormat: "02-Jan-2006",
TimeZone: "America/New_York",
Output: os.Stdout,
}))
```
#### **Custom File Writer**
```go
file, err := os.OpenFile("./123.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer file.Close()
app.Use(logger.New(logger.Config{
Output: file,
}))
```