Skip to content

Commit

Permalink
Merge pull request #3 from gofiber/master
Browse files Browse the repository at this point in the history
Accumulative update @ 07 Mar 2020
  • Loading branch information
koddr committed Mar 7, 2020
2 parents 8acb1df + 0803ed5 commit 778953d
Show file tree
Hide file tree
Showing 20 changed files with 2,581 additions and 864 deletions.
102 changes: 67 additions & 35 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<a href="https://github.com/gofiber/fiber/blob/master/.github/README_tr.md">
<img height="20px" src="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.4.6/flags/4x3/tr.svg">
</a>
<a href="https://github.com/gofiber/fiber/blob/master/.github/README_id.md">
<img height="20px" src="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.4.6/flags/4x3/id.svg">
</a>
<br><br>
<a href="https://github.com/gofiber/fiber/releases">
<img src="https://img.shields.io/github/release/gofiber/fiber?style=flat-square">
Expand Down Expand Up @@ -60,7 +63,7 @@
</a>
</p>
<p align="center">
<b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> build on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://golang.org/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <b>zero memory allocation</b> and <b>performance</b> in mind.
<b>Fiber</b> is an <a href="https://github.com/expressjs/express">Express</a> inspired <b>web framework</b> built on top of <a href="https://github.com/valyala/fasthttp">Fasthttp</a>, the <b>fastest</b> HTTP engine for <a href="https://golang.org/doc/">Go</a>. Designed to <b>ease</b> things up for <b>fast</b> development with <b>zero memory allocation</b> and <b>performance</b> in mind.
</p>

## ⚡️ Quickstart
Expand Down Expand Up @@ -109,16 +112,16 @@ These tests are performed by [TechEmpower](https://github.com/TechEmpower/Framew
- [API endpoints](https://fiber.wiki/context)
- Middleware & [Next](https://fiber.wiki/context#next) support
- [Rapid](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming
- Available in 9 other languages
- Available in 10 other languages
- And much more, [explore Fiber](https://fiber.wiki/)

## 💡 Philosophy

New gophers that make the switch from [Node.js](https://nodejs.org/en/about/) to [Go](https://golang.org/doc/) are dealing with a learning curve before they can start building their web applications or microservices. Fiber, as a **web framework**, was created with the idea of **minimalism** and follow **UNIX way**, so that new gophers can quickly enter the world of Go with a warm and trusted welcome.
New gophers that make the switch from [Node.js](https://nodejs.org/en/about/) to [Go](https://golang.org/doc/) are dealing with a learning curve before they can start building their web applications or microservices. Fiber, as a **web framework**, was created with the idea of **minimalism** and follows the **UNIX way**, so that new gophers can quickly enter the world of Go with a warm and trusted welcome.

Fiber is **inspired** by Express, the most popular web framework on the Internet. We combined the **ease** of Express and **raw performance** of Go. If you have ever implemented a web application on Node.js (_using Express or similar_), then many methods and principles will seem **very common** to you.
Fiber is **inspired** by Express, the most popular web framework on the Internet. We combined the **ease** of Express and **raw performance** of Go. If you have ever implemented a web application in Node.js (_using Express or similar_), then many methods and principles will seem **very common** to you.

We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues) (_and all over the Internet_) to create a **fast**, **flexible** and **friendly** Go web framework for **any** tasks, **deadlines** and developer **skills**! Just like Express does in the JavaScript world.
We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues) (_and all over the Internet_) to create a **fast**, **flexible** and **friendly** Go web framework for **any** task, **deadline** and developer **skill**! Just like Express does in the JavaScript world.

## 👀 Examples

Expand Down Expand Up @@ -153,12 +156,12 @@ func main() {
```

### Serve static files

https://fiber.wiki/application#static
```go
func main() {
app := fiber.New()

app.Static("/public")
app.Static("/", "/public")
// => http://localhost:3000/js/script.js
// => http://localhost:3000/css/style.css

Expand All @@ -174,7 +177,8 @@ func main() {
```

### Middleware & Next

https://fiber.wiki/routing#middleware
https://fiber.wiki/context#next
```go
func main() {
app := fiber.New()
Expand Down Expand Up @@ -205,9 +209,10 @@ func main() {
<summary>📚 Show more code examples</summary>

### Template engines
https://fiber.wiki/application#settings
https://fiber.wiki/context#render

Already supports:

Supported engines:
- [html](https://golang.org/pkg/html/template/)
- [amber](https://github.com/eknkc/amber)
- [handlebars](https://github.com/aymerick/raymond)
Expand Down Expand Up @@ -241,7 +246,7 @@ func main() {
```

### Grouping routes into chains

https://fiber.wiki/application#group
```go
func main() {
app := fiber.New()
Expand All @@ -263,8 +268,8 @@ func main() {
}
```

### Built-in logger

### Middleware logger
https://fiber.wiki/middleware#logger
```go
import (
"github.com/gofiber/fiber"
Expand All @@ -273,7 +278,7 @@ import (

func main() {
app := fiber.New()

// If you want to change default Logger config
loggerConfig := middleware.LoggerConfig{
Format: "${time} - ${method} ${path}\n",
Expand All @@ -288,6 +293,7 @@ func main() {
```

### Cross-Origin Resource Sharing (CORS)
https://fiber.wiki/middleware#cors

[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.

Expand All @@ -311,7 +317,7 @@ func main() {
}
```

Check CORS by passing any domain in `Origin` header:
Check CORS by passing any domain in `Origin` header:

```bash
curl -H "Origin: http://example.com" --verbose http://localhost:3000
Expand Down Expand Up @@ -343,35 +349,40 @@ func main() {
```

### JSON Response

https://fiber.wiki/context#json
```go
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}

func main() {
app := fiber.New()

type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
app.Get("/user", func(c *fiber.Ctx) {
c.JSON(&User{"John", 20})
// {"name":"John", "age":20}
})

// Serialize JSON
app.Get("/json", func(c *fiber.Ctx) {
c.JSON(&User{"John", 20})
// => {"name":"John", "age":20}
c.JSON(&fiber.Map{
"success": true,
"message": "Hi John!",
})
// {"success":true, "message":"Hi John!"}
})

app.Listen(3000)
}
```

### WebSocket support

https://fiber.wiki/application#websocket
```go
func main() {
app := fiber.New()

app.WebSocket("/ws/:name", func(c *fiber.Conn) {
log.Println(c.Params("name"))

app.WebSocket("/ws", func(c *fiber.Conn) {
for {
mt, msg, err := c.ReadMessage()
if err != nil {
Expand All @@ -389,26 +400,33 @@ func main() {
}
})

// Listen on ws://localhost:3000/ws/john
// Listen on ws://localhost:3000/ws
app.Listen(3000)
}
```

### Recover from `panic`

### Recover middleware
https://fiber.wiki/middleware#recover
```go
package main

import (
"github.com/gofiber/fiber"
"github.com/gofiber/fiber/middleware"
)

func main() {
app := fiber.New()

app.Use(middleware.Recover(func(c *fiber.Ctx, err error) {
log.Println(err) // "Something went wrong!"
c.SendStatus(500) // Internal Server Error
})))

app.Get("/", func(c *fiber.Ctx) {
panic("Something went wrong!")
})

app.Recover(func(c *fiber.Ctx) {
c.Status(500).Send(c.Error())
// => 500 "Something went wrong!"
})

app.Listen(3000)
}
```
Expand Down Expand Up @@ -437,6 +455,12 @@ If you want to say **thank you** and/or support the active development of `Fiber

<table>
<tr>
<td align="center">
<a href="https://github.com/gofiber/fiber">
<img src="https://i.stack.imgur.com/frlIf.png" width="100px"></br>
<sub><b>JustDave</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
Expand Down Expand Up @@ -471,3 +495,11 @@ If you want to say **thank you** and/or support the active development of `Fiber
## ⚠️ License

`Fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/blob/master/LICENSE).

[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/0)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/0)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/1)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/1)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/2)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/2)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/3)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/3)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/4)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/4)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/5)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/5)
[![](https://sourcerer.io/fame/Fenny/gofiber/fiber/images/6)](https://sourcerer.io/fame/Fenny/gofiber/fiber/links/6)

0 comments on commit 778953d

Please sign in to comment.