diff --git a/README.md b/README.md index 86e4ef3d..58ae0236 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ People switching from [Node.js](https://nodejs.org/en/about/) to [Go](https://go ## API Documentation -📚 We created an extended **API documentation** (_including examples_), **[click here](https://gofiber.github.io/fiber/)**. +📚 We created an extended **API documentation** (_including examples_), **[Visit fiber.wiki](https://fiber.wiki/)**. ## Benchmark -[![](https://gofiber.github.io/fiber/static/benchmarks/benchmark.png)](https://gofiber.github.io/fiber/#/benchmarks) +[![](https://fiber.wiki/static/benchmarks/benchmark.png)](https://fiber.wiki/#/benchmarks) -👉 **[Click here](https://gofiber.github.io/fiber/#/benchmarks)** to see all benchmark results. +👉 **[Click here](https://fiber.wiki/#/benchmarks)** to see all benchmark results. ## Features @@ -26,7 +26,7 @@ People switching from [Node.js](https://nodejs.org/en/about/) to [Go](https://go - Static files with custom prefix - Middleware with Next support - Express API endpoints -- [Extended documentation](https://gofiber.github.io/fiber/) +- [Extended documentation](https://fiber.wiki/) ## Installing @@ -73,7 +73,7 @@ And now, browse to `http://localhost:8080` and you should see `Hello, World!` on ## Static files -To serve static files, use the [Static](https://gofiber.github.io/fiber/#/?id=static-files) method: +To serve static files, use the [Static](https://fiber.wiki/#/?id=static-files) method: ```go package main @@ -140,7 +140,7 @@ If you want to say **thank you** or/and support active development `gofiber/fibe 1. Add a GitHub Star to project. 2. Tweet about project [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%94%8C%20Fiber%20is%20an%20Express.js%20inspired%20Go%20web%20framework%20build%20on%20%F0%9F%9A%80%20Fasthttp%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber). -3. Help us to translate this `README` and [API Docs](https://gofiber.github.io/fiber/) to another language. +3. Help us to translate this `README` and [API Docs](https://fiber.wiki/) to another language. Thanks for your support! 😘 Together, we make `Fiber`. diff --git a/README_CH.md b/README_CH.md index dc6de0f4..e38a949c 100644 --- a/README_CH.md +++ b/README_CH.md @@ -10,13 +10,13 @@ ## API Documentation -📚 我们创建了一个扩展我们创建了一个扩展 **API documentation** (_包括例子_), **[点击这里](https://gofiber.github.io/fiber/)**. +📚 我们创建了一个扩展我们创建了一个扩展 **API documentation** (_包括例子_), **[点击这里](https://fiber.wiki/)**. ## Benchmark -[![](https://gofiber.github.io/fiber/static/benchmarks/benchmark.png)](https://gofiber.github.io/fiber/#/benchmarks) +[![](https://fiber.wiki/static/benchmarks/benchmark.png)](https://fiber.wiki/#/benchmarks) -👉 **[点击这里](https://gofiber.github.io/fiber/#/benchmarks)** 查看所有基准测试结果. +👉 **[点击这里](https://fiber.wiki/#/benchmarks)** 查看所有基准测试结果. ## Features @@ -26,7 +26,7 @@ - 具有自定义前缀的静态文件 - 具有Next支持的中间件 - Express API端点 -- [Extended documentation](https://gofiber.github.io/fiber/) +- [Extended documentation](https://fiber.wiki/) ## Installing @@ -73,7 +73,7 @@ go run server.go ## Static files -要提供静态文件,请使用 [Static](https://gofiber.github.io/fiber/#/?id=static-files) 方法: +要提供静态文件,请使用 [Static](https://fiber.wiki/#/?id=static-files) 方法: ```go package main @@ -140,7 +140,7 @@ func main() { 1. 将GitHub Star添加到项目中。 2. 关于项目的推文 [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%94%8C%20Fiber%20is%20an%20Express.js%20inspired%20Go%20web%20framework%20build%20on%20%F0%9F%9A%80%20Fasthttp%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber). -3. 帮助我们翻译 `README` 和 [API Docs](https://gofiber.github.io/fiber/) 换一种语言. +3. 帮助我们翻译 `README` 和 [API Docs](https://fiber.wiki/) 换一种语言. 谢谢你的支持! 😘 我们在一起 `Fiber Web Framework` 每天都好. diff --git a/README_RU.md b/README_RU.md index b388ca17..b3b42938 100644 --- a/README_RU.md +++ b/README_RU.md @@ -10,13 +10,13 @@ ## Документация по API -📚 Мы создали расширенную **документацию по API** (_включая примеры_), **[посмотреть](https://gofiber.github.io/fiber/)**. +📚 Мы создали расширенную **документацию по API** (_включая примеры_), **[посмотреть](https://fiber.wiki/)**. ## Бенчмарк -[![](https://gofiber.github.io/fiber/static/benchmarks/benchmark.png)](https://gofiber.github.io/fiber/#/benchmarks) +[![](https://fiber.wiki/static/benchmarks/benchmark.png)](https://fiber.wiki/#/benchmarks) -👉 **[Click here](https://gofiber.github.io/fiber/#/benchmarks)** to see all benchmark results. +👉 **[Click here](https://fiber.wiki/#/benchmarks)** to see all benchmark results. ## Особенности @@ -26,7 +26,7 @@ - Статические файлы с пользовательским префиксом - Middleware с поддержкой `Next()` - Endpoints, как у API Express -- [Расширенная документация](https://gofiber.github.io/fiber/) +- [Расширенная документация](https://fiber.wiki/) ## Установка @@ -73,7 +73,7 @@ go run server.go ## Статичные файлы -Для получения доступа к статичным файлам, используйте метод [Static](https://gofiber.github.io/fiber/#/?id=static-files): +Для получения доступа к статичным файлам, используйте метод [Static](https://fiber.wiki/#/?id=static-files): ```go package main @@ -141,7 +141,7 @@ func main() { 1. Добавьте звёздочку GitHub этому репозиторию. 2. Отправьте твит об этом проекте [в свой Twitter](https://twitter.com/intent/tweet?text=%F0%9F%94%8C%20Fiber%20is%20an%20Express.js%20inspired%20Go%20web%20framework%20build%20on%20%F0%9F%9A%80%20Fasthttp%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber). -3. Помогите нам перевести `README` и [Документацию по API](https://gofiber.github.io/fiber/) на другой язык. +3. Помогите нам перевести `README` и [Документацию по API](https://fiber.wiki/) на другой язык. Спасибо за поддержку! 😘 Вместе мы делаем `Fiber Web Framework` лучше каждый день. diff --git a/docs/getting_started.md b/docs/getting_started.md index 9c72fb64..82435978 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -2,10 +2,9 @@ [![](https://img.shields.io/github/release/gofiber/fiber)](https://github.com/gofiber/fiber/releases) ![](https://img.shields.io/github/languages/top/gofiber/fiber) [![](https://godoc.org/github.com/gofiber/fiber?status.svg)](https://godoc.org/github.com/gofiber/fiber) ![](https://goreportcard.com/badge/github.com/gofiber/fiber) [![GitHub license](https://img.shields.io/github/license/gofiber/fiber.svg)](https://github.com/gofiber/fiber/blob/master/LICENSE) [![Join the chat at https://gitter.im/gofiber/community](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gofiber/community) -!>**IMPORTANT: Always use versioning control using [go.mod](https://blog.golang.org/using-go-modules) to avoid breaking API changes!** +**[Fiber](https://github.com/gofiber/fiber)** is an [Express.js](https://expressjs.com/en/4x/api.html) styled HTTP web framework implementation running on [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for Go (Golang). The package make use of **similar framework convention** as they are in Express. -**[Fiber](https://github.com/gofiber/fiber)** is a router framework build on top of [FastHTTP](https://github.com/valyala/fasthttp), the fastest HTTP package for **[Go](https://golang.org/doc/)**.
-This library is inspired by [Express](https://expressjs.com/en/4x/api.html), one of the most populair and well known web framework for **[Nodejs](https://nodejs.org/en/about/)**. +People switching from [Node.js](https://nodejs.org/en/about/) to [Go](https://golang.org/doc/) often end up in a bad learning curve to start building their webapps, this project is meant to **ease** things up for **fast** development, but with **zero memory allocation** and **performance** in mind. #### Installing diff --git a/middleware/cors.go b/middleware/cors.go index e7a0b79f..fc5b2cd9 100644 --- a/middleware/cors.go +++ b/middleware/cors.go @@ -2,13 +2,17 @@ package middleware import "github.com/gofiber/fiber" +// app.Use(middleware.Cors()) + // Cors : Enable cross-origin resource sharing (CORS) with various options. -func Cors(c *fiber.Ctx, origin ...string) { - o := "*" - if len(origin) > 0 { - o = origin[0] +func Cors(origin ...string) func(*fiber.Ctx) { + return func(c *fiber.Ctx) { + o := "*" + if len(origin) > 0 { + o = origin[0] + } + c.Set("Access-Control-Allow-Origin", o) + c.Set("Access-Control-Allow-Headers", "X-Requested-With") + c.Next() } - c.Set("Access-Control-Allow-Origin", o) - c.Set("Access-Control-Allow-Headers", "X-Requested-With") - c.Next() } diff --git a/middleware/helmet.go b/middleware/helmet.go index 623845e7..d937d6b3 100644 --- a/middleware/helmet.go +++ b/middleware/helmet.go @@ -6,8 +6,25 @@ import ( "github.com/gofiber/fiber" ) +// HelmetOptions https://github.com/helmetjs/helmet#how-it-works +type HelmetOptions struct { + ContentSecurityPolicy string + CrossDomain string + DNSPrefetchControl string // default + ExpectCt string + FeaturePolicy string + FrameGuard string // default + Hpkp string + Hsts string // default + IeNoOpen string // default + NoCache string + NoSniff string // default + ReferrerPolicy string + XSSFilter string // default +} + // Helmet : Helps secure your apps by setting various HTTP headers. -func Helmet() func(*fiber.Ctx) { +func Helmet(opt ...*HelmetOptions) func(*fiber.Ctx) { return func(c *fiber.Ctx) { fmt.Println("Helmet is still under development, this middleware does nothing yet.") c.Next() diff --git a/middleware/morgan.go b/middleware/morgan.go new file mode 100644 index 00000000..38f21c50 --- /dev/null +++ b/middleware/morgan.go @@ -0,0 +1,17 @@ +package middleware + +import ( + "fmt" + "time" + + "github.com/gofiber/fiber" +) + +// Morgan : Simple logger +func Morgan() func(*fiber.Ctx) { + return func(c *fiber.Ctx) { + currentTime := time.Now().Format("02 Jan, 15:04:05") + fmt.Printf("%s \x1b[1;32m%s \x1b[1;37m%s\x1b[0000m, %s\n", currentTime, c.Method(), c.Path(), c.Get("User-Agent")) + c.Next() + } +}