Fix GolangCI issues, Draft new README

pull/75/head
Vic Shóstak 2020-02-07 22:28:18 +03:00
parent dce03337f9
commit 397ece3d24
6 changed files with 98 additions and 64 deletions

View File

@ -1,4 +1,4 @@
# 🚀 Fiber <a href="README_RU.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ru.svg" alt="ru"/></a> <a href="README_CH.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ch.svg" alt="ch"/></a>
# 🚀 Fiber <a href="README_RU.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ru.svg" alt="ru"/></a> <a href="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)
@ -113,7 +113,7 @@ func main() {
// Create new Fiber instance
app := fiber.New()
// Define all used middlewares in Use()
// Define all used middleware in Use()
app.Use(func(c *fiber.Ctx) {
c.Write("Match anything!\n")
@ -134,7 +134,7 @@ func main() {
}
```
## Project assistance
## 👍 Project assistance
If you want to say **thank you** or/and support active development `gofiber/fiber`:
@ -144,7 +144,7 @@ If you want to say **thank you** or/and support active development `gofiber/fibe
Thanks for your support! 😘 Together, we make `Fiber`.
## Stars over time
## ⭐️ Stars over time
<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>

View File

@ -1,14 +1,12 @@
[![Fiber Logo](https://i.imgur.com/zzmW4eK.png)](https://fiber.wiki)
# 🚀 Fiber <a href="README_RU.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ru.svg" alt="ru"/></a> <a href="README_CH.md"><img width="20px" src="https://github.com/gofiber/docs/blob/master/static/flags/ch.svg" alt="ch"/></a>
[Express](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.
[![](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)
[![](https://img.shields.io/github/release/gofiber/fiber)](https://github.com/gofiber/fiber/releases)
[![](https://img.shields.io/badge/godoc-reference-blue.svg?longCache=true&style=flat)](https://pkg.go.dev/github.com/gofiber/fiber?tab=doc)
![](https://img.shields.io/badge/coverage-84%25-brightgreen.svg?longCache=true&style=flat)
![](https://img.shields.io/badge/go-100%25-brightgreen.svg?longCache=true&style=flat)
![](https://img.shields.io/badge/goreport-A+-brightgreen.svg?longCache=true&style=flat)
[![](https://img.shields.io/badge/gitter-chat-brightgreen.svg?longCache=true&style=flat)](https://pkg.go.dev/github.com/gofiber/fiber?tab=doc)
<img align="right" height="160px" src="https://github.com/gofiber/docs/blob/master/static/logo_320px_trans.png" alt="Fiber logo" />
**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.
## ⚡️ Quick start
```golang
package main
@ -26,15 +24,7 @@ func main() {
}
```
## Benchmarks
These tests are performed by [TechEmpower](https://github.com/TechEmpower/FrameworkBenchmarks) and [Go Web](https://github.com/smallnest/go-web-framework-benchmark). If you want to see all results, please visit our [wiki#benchmarks](https://fiber.wiki/#benchmarks).
<p float="left" align="middle">
<img src="https://fiber.wiki/static/benchmarks/benchmark-pipeline.png" width="49%" />
<img src="https://fiber.wiki/static/benchmarks/benchmark_alloc.png" width="49%" />
</p>
## Installation
## ⚙️ Installation
Before installing, [download and install Go](https://golang.org/dl/).
Go `1.11` or higher is required.
@ -46,29 +36,38 @@ Installation is done using the
go get github.com/gofiber/fiber
```
## Features
## 🤖 Benchmarks
* Robust [routing](https://fiber.wiki/#/routing)
* Serve [static files](https://fiber.wiki/#/application?id=static)
* [Extreme performance](https://fiber.wiki/#/benchmarks)
* Low memory footprint
* Express [API endpoints](https://fiber.wiki/#/context)
* Middleware & [Next](https://fiber.wiki/#context?id=next) support
* Rapid server-side programming
* [And much more, click here](https://fiber.wiki/)
These tests are performed by [TechEmpower](https://github.com/TechEmpower/FrameworkBenchmarks) and [Go Web](https://github.com/smallnest/go-web-framework-benchmark). If you want to see all results, please visit our [wiki#benchmarks](https://fiber.wiki/#benchmarks).
<p float="left" align="middle">
<img src="https://fiber.wiki/static/benchmarks/benchmark-pipeline.png" width="49%" />
<img src="https://fiber.wiki/static/benchmarks/benchmark_alloc.png" width="49%" />
</p>
## Philosophy
## 🎯 Main features
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 or micro services. Fiber, as a web framework, was created with the idea of minimalism so new and experienced gophers can rapidly develop web application's.
- Robust [routing](https://fiber.wiki/#/routing)
- Serve [static files](https://fiber.wiki/#/application?id=static)
- [Extreme performance](https://fiber.wiki/#/benchmarks)
- Low memory footprint
- Express [API endpoints](https://fiber.wiki/#/context)
- Middleware & [Next](https://fiber.wiki/#context?id=next) support
- Rapid server-side programming
- [And much more, click here](https://fiber.wiki/)
Fiber is inspired by the Express framework, the most populair web framework on web. We combined the ease of Express and raw performance of Go. If you have ever implemented a web application on Node.js using Express.js, then many methods and principles will seem very common to you.
## 💡 Philosophy
## Examples
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 or micro services. Fiber, as a web framework, was created with the idea of minimalism so new and experienced gophers can rapidly develop web application's.
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 [api documentation](https://fiber.wiki).
Fiber is **inspired** by the Express framework, the most popular web framework on 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.js, then many methods and principles will seem very common to you.
## 👀 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 [API documentation](https://fiber.wiki).
### Static files
_**Static files**_
```golang
// ...
app := fiber.New()
@ -84,22 +83,23 @@ app.Static("/xxx", "./public")
app.Listen(3000)
```
_**Routing**_
### Routing
```golang
// ...
app := fiber.New()
// param
// URL with param
app.Get("/:name", func(c *fiber.Ctx) {
c.Send("Hello, " + c.Params("name"))
})
// optional param
// URL optional param
app.Get("/:name/:lastname?", func(c *fiber.Ctx) {
c.Send("Hello, " + c.Params("name") + " " + c.Params("lastname"))
})
// wildcard
// URL with wildcard
app.Get("/api*", func(c *fiber.Ctx) {
c.Send("/api" + c.Params("*"))
})
@ -107,12 +107,13 @@ app.Get("/api*", func(c *fiber.Ctx) {
app.Listen(3000)
```
_**Middleware**_
### Middleware
```golang
// ...
app := fiber.New()
// match any post route
// Match any post route
app.Post(func(c *fiber.Ctx) {
user, pass, ok := c.BasicAuth()
if !ok || user != "john" || pass != "doe" {
@ -122,14 +123,14 @@ app.Post(func(c *fiber.Ctx) {
c.Next()
})
// match all routes starting with /api
// Match all routes starting with /api
app.Use("/api", func(c *fiber.Ctx) {
c.Set("Access-Control-Allow-Origin", "*")
c.Set("Access-Control-Allow-Headers", "X-Requested-With")
c.Next()
})
// optional param
// Optional param
app.Post("/api/register", func(c *fiber.Ctx) {
username := c.Body("username")
password := c.Body("password")
@ -139,14 +140,15 @@ app.Post("/api/register", func(c *fiber.Ctx) {
app.Listen(3000)
```
_**404 Handling**_
### 404 Handling
```golang
// ...
app := fiber.New()
// ..application routes
// ... app routes here
// last route
// The last route
app.Use(func (c *fiber.Ctx) {
c.SendStatus(404)
})
@ -154,17 +156,19 @@ app.Use(func (c *fiber.Ctx) {
app.Listen(3000)
```
_**JSON Response**_
### JSON Response
```golang
// ...
app := fiber.New()
// Data structure
type Data struct {
Name string `json:"name"`
Age int `json:"age"`
}
// last route
// The last route
app.Get("/json", func (c *fiber.Ctx) {
c.JSON(&Data{
Name: "John",
@ -175,7 +179,20 @@ app.Get("/json", func (c *fiber.Ctx) {
app.Listen(3000)
```
## 👍 Project assistance
## License
If you want to say **thank you** or/and support active development `gofiber/fiber`:
`gofiber/fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/master/LICENSE).
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://fiber.wiki/) to another language.
Thanks for your support! 😘 Together, we make `Fiber`.
## ⭐️ Stars over time
<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>
## ⚠️ License
`Fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/master/LICENSE).

View File

@ -1,14 +1,12 @@
package fiber
import (
"sync"
"testing"
)
var wg sync.WaitGroup
// var wg sync.WaitGroup
func Test_Connect(t *testing.T) {
return
// app := New()
// app.Banner = false
//

View File

@ -236,7 +236,9 @@ func Test_FormValue(t *testing.T) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
writer.WriteField("name", "john")
if err := writer.WriteField("name", "john"); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
writer.Close()
req, _ := http.NewRequest("POST", "/test", body)
contentType := fmt.Sprintf("multipart/form-data; boundary=%s", writer.Boundary())
@ -450,7 +452,9 @@ func Test_MultipartForm(t *testing.T) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
writer.WriteField("name", "john")
if err := writer.WriteField("name", "john"); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
writer.Close()
req, _ := http.NewRequest("POST", "/test", body)
contentType := fmt.Sprintf("multipart/form-data; boundary=%s", writer.Boundary())

View File

@ -158,12 +158,16 @@ func Test_JSON(t *testing.T) {
}
app := New()
app.Get("/test", func(c *Ctx) {
c.Json("")
if err := c.JSON(""); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
data := SomeStruct{
Name: "Grame",
Age: 20,
}
c.JSON(data)
if err := c.JSON(data); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
})
req, _ := http.NewRequest("GET", "http://example.com/test", nil)
resp, err := app.Test(req)
@ -216,12 +220,16 @@ func Test_JSONP(t *testing.T) {
}
app := New()
app.Get("/test", func(c *Ctx) {
c.Jsonp("")
if err := c.JSONP(""); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
data := SomeStruct{
Name: "Grame",
Age: 20,
}
c.JSONP(data, "alwaysjohn")
if err := c.JSONP(data, "alwaysjohn"); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
})
req, _ := http.NewRequest("GET", "http://example.com/test", nil)
resp, err := app.Test(req)
@ -543,8 +551,12 @@ func Test_XML(t *testing.T) {
}
app := New()
app.Get("/test", func(c *Ctx) {
c.Xml("")
c.XML(person{"John", 50})
if err := c.XML(""); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
if err := c.XML(person{"John", 50}); err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
})
req, _ := http.NewRequest("GET", "http://example.com/test", nil)
resp, err := app.Test(req)

View File

@ -124,7 +124,10 @@ func (r *Fiber) Test(req *http.Request) (*http.Response, error) {
// Create fake connection
conn := &conn{}
// Pass HTTP request to conn
conn.r.Write(reqRaw)
_, err = conn.r.Write(reqRaw)
if err != nil {
return nil, err
}
// Serve conn to server
channel := make(chan error)
go func() {