New readme

pull/86/head
Fenny 2020-02-10 01:52:11 +01:00
parent 1e7df547ba
commit c7f4db4980
1 changed files with 90 additions and 89 deletions

85
.github/README_NEW.md vendored
View File

@ -1,10 +1,8 @@
<img height="160px" src="https://github.com/gofiber/docs/blob/master/static/logo_320px_trans.png" alt="Fiber logo" /> ![](https://i.imgur.com/PFEjoFz.png)<a href="https://github.com/gofiber/fiber/blob/master/.github/readme_ru.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ru.svg" alt="ru"/></a> <a href="https://github.com/gofiber/fiber/blob/master/.github/readme_ch.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ch.svg" alt="ch"/></a>
# 🚀 Fiber <a href="https://github.com/gofiber/fiber/blob/master/.github/readme_ru.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ru.svg" alt="ru"/></a> <a href="https://github.com/gofiber/fiber/blob/master/.github/readme_ch.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ch.svg" alt="ch"/></a>
[![](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) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/gofiber/fiber) [![](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) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/gofiber/fiber)
**Fiber** is an [Express.js](https://github.com/expressjs/express) **inspired** web framework build on [Fasthttp](https://github.com/valyala/fasthttp) for [Go](https://golang.org/doc/). Designed to **ease** things up for **fast** development with **zero memory allocation** and **performance** in mind. **Fiber** is an [Expressjs](https://github.com/expressjs/express) **inspired** web framework build on [Fasthttp](https://github.com/valyala/fasthttp) for [Go](https://golang.org/doc/). Designed to **ease** things up for **fast** development with **zero memory allocation** and **performance** in mind.
## ⚡️ Quick start ## ⚡️ Quick start
@ -45,7 +43,7 @@ These tests are performed by [TechEmpower](https://github.com/TechEmpower/Framew
<img src="https://github.com/gofiber/docs/blob/master/static/benchmarks/benchmark_alloc.png" width="49%" /> <img src="https://github.com/gofiber/docs/blob/master/static/benchmarks/benchmark_alloc.png" width="49%" />
</p> </p>
## 🎯 Main features ## 🎯 Features
- Robust [routing](https://fiber.wiki/routing) - Robust [routing](https://fiber.wiki/routing)
- Serve [static files](https://fiber.wiki/application#static) - Serve [static files](https://fiber.wiki/application#static)
@ -54,7 +52,7 @@ These tests are performed by [TechEmpower](https://github.com/TechEmpower/Framew
- Express [API endpoints](https://fiber.wiki/context) - Express [API endpoints](https://fiber.wiki/context)
- Middleware & [Next](https://fiber.wiki/context#next) support - Middleware & [Next](https://fiber.wiki/context#next) support
- Rapid server-side programming - Rapid server-side programming
- And much more, [visit our Wiki](https://fiber.wiki/) - And much more, [explore Fiber](https://fiber.wiki/)
## 💡 Philosophy ## 💡 Philosophy
@ -64,57 +62,58 @@ Fiber is **inspired** by the Express framework, the most popular web framework o
## 👀 Examples ## 👀 Examples
Listed below are some of the common examples. If you want to see more code examples, please visit Fiber community [Cookbook repository](https://github.com/gofiber/recipes) or [API documentation](https://fiber.wiki). 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://fiber.wiki).
### Static files ### Static files
```go ```go
// ... func main() {
app := fiber.New() app := fiber.New()
// Without prefix
app.Static("./public") app.Static("./public")
// => http://localhost:3000/js/script.js // => http://localhost:3000/js/script.js
// => http://localhost:3000/css/style.css // => http://localhost:3000/css/style.css
// With prefix app.Static("/prefix", "./public")
app.Static("/your-prefix", "./public") // => http://localhost:3000/prefix/js/script.js
// => http://localhost:3000/prefix/css/style.css
// => http://localhost:3000/your-prefix/js/script.js
// => http://localhost:3000/your-prefix/css/style.css
app.Listen(3000) app.Listen(3000)
}
``` ```
### Routing ### Routing
```go ```go
// ... func main() {
app := fiber.New() app := fiber.New()
// URL with param // GET /john
app.Get("/:name", func(c *fiber.Ctx) { app.Get("/:name", func(c *fiber.Ctx) {
c.Send("Hello, " + c.Params("name")) fmt.Printf("Hello %s!", c.Params("name"))
// => Hello john!
}) })
// URL optional param // GET /john
app.Get("/:name/:lastname?", func(c *fiber.Ctx) { app.Get("/:name/:age?", func(c *fiber.Ctx) {
c.Send("Hello, " + c.Params("name") + " " + c.Params("lastname")) fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
// => Name: john, Age:
}) })
// URL with wildcard // GET /api/register
app.Get("/api*", func(c *fiber.Ctx) { app.Get("/api*", func(c *fiber.Ctx) {
c.Send("/api" + c.Params("*")) fmt.Printf("/api%s", c.Params("*"))
// => /api/register
}) })
app.Listen(3000) app.Listen(3000)
}
``` ```
### Middleware ### Middleware
```go ```go
// ... func main() {
app := fiber.New() app := fiber.New()
// Match any post route // Match any post route
@ -142,63 +141,65 @@ app.Post("/api/register", func(c *fiber.Ctx) {
}) })
app.Listen(3000) app.Listen(3000)
}
``` ```
### 404 Handling ### 404 Handling
```go ```go
// ... func main() {
app := fiber.New() app := fiber.New()
// ... app routes here // Serve static files from "public" directory
app.Static("./public")
// The last route // Last middleware
app.Use(func (c *fiber.Ctx) { app.Use(func (c *fiber.Ctx) {
c.SendStatus(404) c.SendStatus(404) // => 404 "Not Found"
}) })
app.Listen(3000) app.Listen(3000)
}
``` ```
### JSON Response ### JSON Response
```go ```go
// ... func main() {
app := fiber.New() app := fiber.New()
// Data structure type User struct {
type Data struct {
Name string `json:"name"` Name string `json:"name"`
Age int `json:"age"` Age int `json:"age"`
} }
// Return JSON data // Serialize JSON
app.Get("/json", func (c *fiber.Ctx) { app.Get("/json", func (c *fiber.Ctx) {
c.JSON(&Data{ c.JSON(&User{"John", 20})
Name: "John",
Age: 20,
})
}) })
app.Listen(3000) app.Listen(3000)
}
``` ```
## 💬 What people say about Fiber? ## 💬 Media
- [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) _by [Vic Shóstak](https://github.com/koddr), 03 Feb 2020_ - [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) _by [Vic Shóstak](https://github.com/koddr), 03 Feb 2020_
## 👍 Project assistance ## 👍 Contribute
If you want to say **thank you** or/and support active development `gofiber/fiber`: If you want to say **thank you** and/or support the active development of `fiber`:
1. Add a GitHub Star to project. 1. Add a GitHub Star to project.
2. Tweet about project [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber). 2. Tweet about project [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber).
3. Write review and usage articles on [Medium](https://medium.com/), [Dev.to](https://dev.to/) and personal blogs. 3. Write a review or tutorial on [Medium](https://medium.com/), [Dev.to](https://dev.to/) or personal blog.
4. Help us to translate this `README` and [API Docs](https://fiber.wiki/) to another language. 4. Help us to translate this `README` and [API Docs](https://fiber.wiki/) to another language.
Thanks for your support! 😘 Together, we make `Fiber`. <a href="https://www.buymeacoffee.com/fenny" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
### ⭐️ Stars over time Thanks for your support! Together, we make `Fiber`.
### ⭐️ Stars
<a href="https://starchart.cc/gofiber/fiber" rel="nofollow"><img src="https://starchart.cc/gofiber/fiber.svg" alt="Stars over time" style="max-width:100%;"></a> <a href="https://starchart.cc/gofiber/fiber" rel="nofollow"><img src="https://starchart.cc/gofiber/fiber.svg" alt="Stars over time" style="max-width:100%;"></a>