Coder Social home page Coder Social logo

gofiber / fiber Goto Github PK

View Code? Open in Web Editor NEW
31.3K 271.0 1.6K 222.11 MB

⚡️ Express inspired web framework written in Go

Home Page: https://gofiber.io

License: MIT License

Go 99.92% Makefile 0.08%
go golang fiber web fast flexible friendly rest-api performance nodejs

fiber's People

Contributors

ajf-sa avatar anatolelucet avatar bestgopher avatar codemicro avatar dependabot[bot] avatar dozheiny avatar efectn avatar fenny avatar fufuok avatar gaby avatar hi019 avatar jfcg avatar kamandlou avatar kiyonlin avatar klipitkas avatar koddr avatar larrylv avatar leonklingele avatar li-jin-gou avatar marvinjwendt avatar nickajacks1 avatar r-52 avatar renanbastos93 avatar renewerner87 avatar sixcolors avatar sujit-baniya avatar trim21 avatar vecpeng avatar wangjq4214 avatar xenowits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fiber's Issues

c.Body() can't read raw data

I don't get data from c.Body ("email") when I request via postman with Raw Body

Raw Data

{
  "email": "[email protected]"
}

Code snippet

package main

import "github.com/gofiber/fiber"

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

  app.Post("/login", func (c *fiber.Ctx) {
    c.Body("email") // no value here
  })

  app.Listen(8080)
}

🔥 add an interface for serving a custom net.Listener

Is your feature request related to a problem?
no
Describe the solution you'd like
something along the lines of

app := fiber.New()
ln, err := net.Listen("unix", "/tmp/sock.d")
app.Serve(ln)

Describe alternatives you've considered
editing the source code to add this functionality directly
Additional context

🐞 Color residue

Fiber version/commit
v1.4.2

Issue description
When I run the build binary and exit color residue.(cmd, powershell,powershell core)

Expected behavior
no color residue

Steps to reproduce
In windows: run binary

Code snippet

package main

import "github.com/gofiber/fiber"

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

	app.Get("/", func(c *fiber.Ctx) {
		c.Send("Hello World!")
	})

	app.Listen("localhost:8080")
}

image

How do i use other flag parse tools ,like kingpin🤔

Question description
fiber.New() calls flag.Parse 。but when i use kingpin,they are in conflict.
i think the fiber.New() may should not call flag.Parse() . What do you think?
Could there be another solution?Sorry, I'm new to golang.
Code snippet (optional)

package main

import (
	"github.com/gofiber/fiber"
	"gopkg.in/alecthomas/kingpin.v2"
	"os"
)

func main()  {
	var testFlag string
	application := kingpin.New("demo", "demo")
	application.Flag("test","kinping flag").Default("test").StringVar(&testFlag)
	application.Parse(os.Args[1:])
	server := fiber.New()
	server.Listen(8080)
}

🔥 Request Validation

Is your feature request related to a problem?
No

Describe the solution you'd like
Fiber has BodyParser function to parse request into the given interface. We can check that the interface has the Validation method and call it to see the parsed request is valid or not.

Describe alternatives you've considered
Validation may seem like an overkill feature, but I think it can reduce the handler code that is written for fiber.

Additional context

The following code shows a request with its validation method.

package request

import (
	"time"

	validation "github.com/go-ozzo/ozzo-validation"
	"github.com/go-ozzo/ozzo-validation/is"
)

// URL represents short URL creation request
type URL struct {
	URL    string     `json:"url"`
	Name   string     `json:"name"`
	Expire *time.Time `json:"expire"`
}

// Validate URL request
func (r URL) Validate() error {
	return validation.ValidateStruct(&r,
		validation.Field(&r.URL, validation.Required, is.URL),
	)
}

Fiber can check the validation method and call it if it is there on the given request.

🤔 Does Fiber support Hot reload ?

Just tried fiber. and the very first thing i feel missing was the hot reload.
I'm coming from a python background where Flask has a feature like development=True parameter to enable hot reload (reflect result in server instantly after changing the code).

🔥 Add some middleware

Is your feature request related to a problem?

Describe the solution you'd like
Looger、Recovery(is necessary in the development)
Ggzip(Currently Static() provides compression, but cannot be customized)
CORS、CSRF、JWT Auth etc...

Describe alternatives you've considered
Are there plans for these middleware?

Additional context

🐞 bodyparser error when using with javascript fetch

Fiber version/commit
Fiber v1.8.0
Issue description
I get this error when trying to use body-parser with content-type: "application/json"
Error on /login: schema: invalid path "{"username":"test","password":"test"}"
Expected behavior

Steps to reproduce
JS fetch with gofiber api

Code snippet
Javascript:

async function handleLogin(){
        const res = await fetch('/auth/login',{
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ "username": username, "password": password})
        });

GO/Fiber:

package main

import "github.com/gofiber/fiber"


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

  type User struct{
    Username string `json:"username", form:"username"` 
    Password string `json:"username", form:"username"`
}
auth:= app.Group("/auth")
auth.Post("/login", func(c *fiber.Ctx){
	var user User
	if err := c.BodyParser(&user); err != nil {
		fmt.Println("Error on /login: ", err)
        c.JSON(fiber.Map{
			"result" : "error",
			"message" : "Error trying to login",
		})
		return
	}
}

🔥 Add a shortcut for map like gin.H

Is your feature request related to a problem?
No

Describe the solution you'd like

c.JSON(fiber.H{
    "field1": someStructData1,
    "field2": someStructData2,
})
// H is a shortcut for map[string]interface{}
type H map[string]interface{}

Describe alternatives you've considered

Additional context

🔥 Router chi

I know that you have designed the router but, if you know about chi, it has been designed to be simple, robust, without external dependencies and it's being used at sites like CloudFlare or Heroku.

https://github.com/go-chi/chi

🤔 Trailer Headers?

Question description

👋 I was pleasantly surprised by this library and wanted to learn about adding (advocating?) for HTTP Trailer support.

I would like to try this library out with a problem that requires streaming and trailers are very helpful in this case.

Further reading: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer

I reviewed the documentation for Fiber to learn if this was possible. It does not appear to be the case. I did further research and it seems that the underlying http layer does not yet support Traillers (yet) valyala/fasthttp#210. The messaging in the Issue is promising and so I was wondering/hoping if this is something the Fiber team could get behind and advocate for as a desired use case?

Best of luck on this project!

🤔 How to register a Prometheus handler

I'm trying to register the Prometheus handler to track some metrics from the application I'm writing but I cannot find a way. I managed to to the following:

package main

import (
  "github.com/gofiber/fiber"
  "github.com/prometheus/client_golang/prometheus/promhttp"
  "github.com/valyala/fasthttp/fasthttpadaptor"

func main() {
  app := fiber.New()
  
  p := fasthttpadaptor.NewFastHTTPHandler(promhttp.Handler())

  app.Get("/metrics", func(c *fiber.Ctx) {
    p(c.Fasthttp)
  })

  app.Get("/", func(c *fiber.Ctx){
    c.Send("Hello, World!")
  })

  app.Get("/404", func(c *fiber.Ctx){
    c.Status(4040).Send("Where did I put it?")
  })

  app.Listen(3000)
}

And it does respond to the requests on /metrics with some data that seems reasonable. Only problem it doesn't seem to count the responses correctly.

(the two endpoints / and /404 are there exactly to try it).

🥳 v1.8.0 release notes!

Fiber v1.8.0 #189

go get -u github.com/gofiber/fiber

[NEW] app.Settings.Immutable / https://fiber.wiki/application#settings

[RENAME] Settings.TemplateFolder-> Settings.TemplateFolder https://fiber.wiki/context#render
[RENAME] Settings.TemplateEngine-> Settings.TemplateEngine https://fiber.wiki/context#render
[RENAME] Settings.TemplateExtension-> Settings.TemplateExtension https://fiber.wiki/context#render

[UPDATE] app.METHOD(path string, handlers ...func(*Ctx)) https://fiber.wiki/application#http-methods
[UPDATE] *Cookie https://fiber.wiki/context#cookie
[UPDATE] ctx.Cookie(*Cookie) https://fiber.wiki/context#cookie
[UPDATE] Removed path params for WebSocket https://fiber.wiki/application#websocket
[UPDATE] Update websocket to v1.4.2

[FIX] Immutable values #185
[FIX] Stronger typed API #178
[FIX] Argument conflict #159
[FIX] Convert Recover error
[FIX] Bundle template dependencies
[FIX] Many internal optimizations

🐞 Document clearly that properties of the request ctx are invalid after the handler returns

Fiber version/commit: Latest
Issue description
Not sure if this is intentional or somewhat of a bug.
Currently, many properties of the request context are returned as strings but are unsafe to persist after the handler has returned (due to unsafe conversion here).

Expected behavior
It should be possible to safely store request properties for reuse after the handler has returned.

Steps to reproduce
See code snippet. Send a few requests in quick succession, e.g.:

for (( c=1; c<=10; c++ )); do   curl "http://localhost:3000/$c";   done

The second fmt.Printf will not output the correct value.

Code snippet

package main
 
import (
        "fmt"
        "time"
 
        "github.com/gofiber/fiber"
)
 
func main() {
        app := fiber.New()
 
        app.Get("/:number", func(c *fiber.Ctx) {
                number := c.Params("number")
                go myfunc(number)
                c.Send(number)
        })
        app.Listen(3000)
}
func myfunc(number string) {
        fmt.Printf("number is %s \n", number)
        time.Sleep(1 * time.Second)
        fmt.Printf("number is now %s \n", number)
}

🔥 Consider adding support for custom Context

Is your feature request related to a problem?
I find myself in need to instantiate a validator and pass it to all the routes. I don't want to have any singletons in the application and so I am looking for a way to extend fiber.Context.

Describe the solution you'd like
I would like to be able to extend the Context with my own custom Context which contains a 'Validator' property which I can set at server startup. The custom Context would be passed to all the routes and I could access the custom properties when needed in my routes.

Describe alternatives you've considered
The alternative is to have a singleton that I can access from my routes. But we all know why Singletons are not a good idea.

Another alternative would be to have a middleware to do this, but I don't want to instantiate a validator on every request.

🔥 Fast logger middleware

Is your feature request related to a problem? Please describe.

I'm not sure if there were any plans to write your own logger (as middleware?), but it would be very cool to add a logger from Uber — zap. It's blazing fast, structured, leveled logging system.

Describe the solution you'd like

For one of my side project (Create Go App, to be exact), I created web app template for Fiber with example usage of zap logger:

Describe alternatives you've considered

As alternative solution, I know only Logrus, but he's very slow and doesn't have flexible structure for configuring (really, when I read zap's docs and source code, I found every things, which I wanted to re-configure).

Therefore, I don't recommend to use Logrus for Fiber, but good to know! 😉

Additional context

I'm ready to discus about this various feature for every web frameworks and may (want) help to write logger middleware, if needed. Please, let me know what you think!

🐞 Color output problem on Windows

Fiber version
1.5.0

Hi, this problem occurs if you use Windows CMD to run fiber:
image

Full Windows color support could possibly be accomplished by using the "Windows Way" of the fathi/color package:
image

This problem also occurs if you use inbuilt terminals (in e.g. IntelliJ IDEA):
image

Add a License

Is your feature request related to a problem?
By default in most jurisdictions, any creative endeavor is copyrighted ("all rights reserved").
This makes using the project difficult, legally speaking, especially in environments where that's a concern (even if no one has the intention of starting a legal action).

Describe the solution you'd like
Add a LICENSE file.
Optionally, also have some form of CLA or similar (at least for already-contributed-contributors).
I personally prefer the Unlicense (available under choose-a-license), but any license would be fine.

Describe alternatives you've considered
Alternatively, you could grant individual licenses to anyone that asks, but that places undue burden on the project maintainers.
Regarding license choices, other popular alternatives include MIT and GPL3.

Additional context

🎉 v1.7.x release notes!

Fiber v1.7.1

go get -u github.com/gofiber/fiber

[NEW] ctx.BodyParser / https://fiber.wiki/context#bodyparser
[NEW] ctx.Error / https://fiber.wiki/context#error
[NEW] ctx.Next / https://fiber.wiki/context#next
[NEW] ctx.Render / https://fiber.wiki/context#render
[NEW] app.New / https://fiber.wiki/application#settings
[NEW] app.Recover / https://fiber.wiki/application#recover
[NEW] app.Group / https://fiber.wiki/application#group
[NEW] app.Settings / https://fiber.wiki/application#settings
[NEW] app.WebSocket / https://fiber.wiki/application#websocket
[NEW] app.Test / https://fiber.wiki/application#test
[NEW] fiber.Map / #153

[FIX] G104 (CWE-703) #168
[FIX] Flag redefined #167
[FIX] Group nesting #155
[FIX] Fix logo #160
[FIX] JSON err handling #126
[FIX] Add windows to tests #119
[FIX] Banner issue #109
[FIX] Static wildcard support #71
[FIX] Unit testing #41
[FIX] Gosec #5
[FIX] Default static files #3
[FIX] ctx.SaveFile #1

[DEPRECATE] ctx.BasicAuth
[DEPRECATE] ctx.Json
[DEPRECATE] ctx.JsonBytes
[DEPRECATE] ctx.JSONBytes
[DEPRECATE] ctx.JsonString
[DEPRECATE] ctx.JSONString
[DEPRECATE] ctx.Xml
[DEPRECATE] ctx.XML
[DEPRECATE] app.Prefork
[DEPRECATE] app.Engine
[DEPRECATE] app.Banner

If you got suggestions, ideas or criticism please create a new issue.

🤔 Is there any way for handling JSON error?

Question description
I have used gofiber for creating a REST API with JSON. The JSON function returns error so I must handle it every time in responses. Is there any better way of doing this?

Code snippet (optional)

package main

import "github.com/gofiber/fiber"

func main() {
  app := fiber.New()
  app.Get("/json", func (c *fiber.Ctx) {
    if err := c.Status(200).JSON("Hello World"); err != nil {
      panic(err)
    }
  })
}

🤔 How to modify fiber.Ctx?

Question description

In Express, it's possible to dangle any sort of custom methods or properties from the request/response objects via middleware. I can't see anything in the documentation of how to do this in Fiber.

For instance, I want to write middleware that deals with some authentication that gives me an API in my route handlers that allows me to check for permissions or call an upstream service, how would this be done?

🔥 Query params

I can't find any normal way to get a query string params without using raw fasthttp queryString
Something like that can be very useful:

app.Get("/", func(c *fiber.Ctx) {
  queryValue := c.Query().Get("param_key")
})

Thanx!

🤔 G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)

Based on new pipeline security, we need to treat errors

[/home/runner/work/fiber/fiber/context.go:107] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
  > conn.Close()

I saw this message then we need to treat possible error returns method close.
https://github.com/gofiber/fiber/blob/master/context.go#L107

Suggestion

func releaseConn(conn *Conn) {
	if err := conn.Close(); err != nil {
             ...
        }
	conn.params = nil
	conn.values = nil
	conn.Conn = nil
	poolConn.Put(conn)
}

🏎️ v1.8.2 changelog

Fiber v1.8.2

go get -u github.com/gofiber/fiber/...

[NEW] app.Settings.BodyLimit https://fiber.wiki/application#settings
[NEW] middleware.Recover(handle ...func(*Ctx, error)) https://fiber.wiki/middleware#recover

[UPDATED] app.Static(prefix, root string) / https://fiber.wiki/application#static
[UPDATED] app.Listen(address interface{}, tlsconfig ...*tls.Config) / https://fiber.wiki/application#listen

[FIX] Allow TLS config #200 / https://fiber.wiki/application#listen
[FIX] Fiber router optimizations
[FIX] app.Settings.Immutable / this will now also keep []byte returns immutable
[FIX] ctx.Next / allows to continue after other routes finished
https://fiber.wiki/context#next

[DEPRECATED] app.Recover()
[DEPRECATED] settings.GETOnly
[DEPRECATED] settings.IdleTimeout
[DEPRECATED] settings.Concurrency
[DEPRECATED] settings.ReadTimeout
[DEPRECATED] settings.WriteTimeout
[DEPRECATED] settings.TCPKeepalive
[DEPRECATED] settings.MaxConnsPerIP
[DEPRECATED] settings.ReadBufferSize
[DEPRECATED] settings.WriteBufferSize
[DEPRECATED] settings.ConcurrencySleep
[DEPRECATED] settings.DisableKeepAlive
[DEPRECATED] settings.ReduceMemoryUsage
[DEPRECATED] settings.MaxRequestsPerConn
[DEPRECATED] settings.TCPKeepalivePeriod

🧬 v1.8.1 changelog

Fiber v1.8.1

go get -u github.com/gofiber/fiber/...

[NEW] app.Settings.Immutable / https://fiber.wiki/application#settings
[NEW] app.Settings.Compression / https://fiber.wiki/application#settings

[NEW] Ctx.Compress / https://fiber.wiki/context#compress
[NEW] Ctx.Range / https://fiber.wiki/context#range heart @hanFengSan

[NEW] middleware.BasicAuth / https://fiber.wiki/middleware#basicauth
[NEW] middleware.CORS / https://fiber.wiki/middleware#cors
[NEW] middleware.Limiter / https://fiber.wiki/middleware#limiter
[NEW] middleware.Logger / https://fiber.wiki/middleware#logger
[NEW] middleware.RequestID / https://fiber.wiki/middleware#requestid
[NEW] middleware.Helmet / https://fiber.wiki/middleware#helmet

[FIX] Internal optimizations

🔥 app.Group seems impossible to nest multiple layers

Is your feature request related to a problem?
app.Group seems impossible to nest multiple layers like gin

Describe the solution you'd like

//my api module
apiRouter := app.Group("/api")
{
	authRouter := apiRouter.Group("/auth")
	{
		authRouter.POST("/login", auth.Login)
		authRouter.GET("/tokenRefresh", middleware.JWTAuth(), auth.TokenRefresh)
	}
	v1Router := apiRouter.Group("/v1", middleware.JWTAuth())
	{
		managerRouter := v1Router.Group("/managers")
		{
			managerRouter.POST("", manager.Add)
		}
		testRouter := v1Router.Group("/test")
		{
			testRouter.GET("/redisSet", test.RedisSet)
		}
	}
	v2Router := apiRouter.Group("/v2")
	{
		managerRouter := v2Router.Group("/manager")
		{
			managerRouter.POST("/add", v2manager.Add)
		}
	}
}

Describe alternatives you've considered

Additional context

[🐞] Found 3 gosec issues: CWE-78 and CWE-242

Your environment:

  • Fiber Web Framework [e.g. 1.2.3]: 1.2.3
  • OS [e.g. macOS 10.14.6]: macOS 10.14.6
  • Golang [e.g. 1.13.7]: 1.13.7

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Install securego/gosec
  2. Run $ gosec ./...
  3. See security report:

Issue G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments:

[/Users/koddr/CodeProjects/fiber/listen.go:101] - G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments (Confidence: HIGH, Severity: MEDIUM)
  > exec.Command(os.Args[0], "-prefork", "-child")

Issue G103 (CWE-242): Use of unsafe calls should be audited:

[/Users/koddr/CodeProjects/fiber/utils.go:82] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&b)

[/Users/koddr/CodeProjects/fiber/utils.go:86] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&s)

Expected behavior

No security issues on report.

Screenshots

No need.

Additional context

Full console output:

$ sw_vers

ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G2022

$ go version 

go version go1.13.7 darwin/amd64

$ gosec ./...

[gosec] 2020/02/02 12:32:41 Including rules: default
[gosec] 2020/02/02 12:32:41 Excluding rules: default
[gosec] 2020/02/02 12:32:41 Import directory: /Users/koddr/CodeProjects/fiber
[gosec] 2020/02/02 12:32:42 Checking package: fiber
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/application.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/context.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/listen.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/methods.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/request.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/response.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/router.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/static.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/status.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/types.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/utils.go
[gosec] 2020/02/02 12:32:42 Import directory: /Users/koddr/CodeProjects/fiber/middleware
[gosec] 2020/02/02 12:32:42 Checking package: middleware
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/middleware/cors.go
[gosec] 2020/02/02 12:32:42 Checking file: /Users/koddr/CodeProjects/fiber/middleware/helmet.go

Results:

[/Users/koddr/CodeProjects/fiber/listen.go:101] - G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments (Confidence: HIGH, Severity: MEDIUM)
  > exec.Command(os.Args[0], "-prefork", "-child")

[/Users/koddr/CodeProjects/fiber/utils.go:82] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&b)

[/Users/koddr/CodeProjects/fiber/utils.go:86] - G103 (CWE-242): Use of unsafe calls should be audited (Confidence: HIGH, Severity: LOW)
  > unsafe.Pointer(&s)

Summary:
   Files: 13
   Lines: 1671
   Nosec: 0
  Issues: 3

🔥 Consider strong typing for API

Is your feature request related to a problem?
Hi!

In Go (IMO) it is considered bad practice to use interface{} if strongly typed API can be implemented.
I understand that idea is to have similarity with the expressjs library, but now developer has to visit documentation/source to identify what are proper params types for the routing function.

Also I think strongly typed API is one of things developers look after when choosing framework. It also can decrease amount of runtime checks and will show errors/mistypes during compile time.

Describe the solution you'd like
As an example for routing function:

func (app *App) Get(
    path string, 
    handler func()(ctx *Ctx), 
    middlewares ...func()(ctx *Ctx)
) App* {
    ...
}

Describe alternatives you've considered
Leave it as it is ¯\(ツ)

🔥 Add Websocket Support

Is your feature request related to a problem? No

Describe the solution you'd like: I'd like to see the ability to promote a request to a websocket connection and handle pub-sub messaging therein. This is a big feature present in other libraries like gorilla and it would make fiber more competitive.

Describe alternatives you've considered: Use a different web library.

Additional context: None.

🤔 always get empty JSON response

Question description

  • I always got empty {} from JSON response.
  • no error is returned from the c.JSON() method.
  • I tested in Postman, the response is always an empty object like {}. with JSONP method, the response is always callback{}.
  • I don't know what happened or how to dig into this problem.
  • version: 1.7.0

Code snippet (optional)

type status struct {
	code    int32
	message string
}

...
       data := status{
		code:    2,
		message: "hello wolrd",
	}
	if err := c.JSON(data); err != nil {
		log.Printf("error in response %v", err)
	}

🔥 Support GZip / Deflate

Is your feature request related to a problem?
Now, the gzip is built in Static(),so I can't customize which paths to open gzip and which file sizes to open gzip

Describe the solution you'd like
In my project,i need open gzip for staticfiles,at the same time, i want open gzip for restful api module(when the response is bigger than 4kb)

Describe alternatives you've considered
gzip be removed from Static() and exist as a official middleware

Additional context

🤔 How do I Set/Get data in context?

Question description
I want save the user information in JWT middleware and get it in the routing handler

Code snippet (optional)
In gin,i'll do it like this:

main.go

package main

func main() {
  app := fiber.New()
  app.Use("/api", midlleware.JwtAuth)
  app.Get("/api/v1/manager", api.ManagerGet)
}

middleware/jwt.go

package middleware

func JwtAuth() {
  // parse authorization
  c.Set("claims", claims)
  c.Next()
}

api/v1/manager.go

package api

func ManagerGet(c *fiber.Ctx) {
  claims, err := c.Get("claims")
}

🌐 Translate Fiber (i18n)

💡 Translation status

Fiber README is already translated into 9 languages:

  • 🇷🇺 Russian (RU)
  • 🇪🇸 Spanish (ES)
  • 🇨🇳 Chinese (ZH_CH)
  • 🇯🇵 Japanese (JA)
  • 🇵🇹 Portuguese (PT)
  • 🇩🇪 German (DE)
  • 🇰🇷 South Korean (KO)
  • 🇫🇷 French (FR)
  • 🇹🇷 Turkish (TR)

Fiber official documentation is already translated into 4 languages:

❗️ This translations on hold. We're preparing to re-write English docs after release Fiber v1.8.

- [x] 🇷🇺 Russian (RU)
- [ ] 🇪🇸 Spanish (ES)
- [x] 🇨🇳 Chinese (ZH_CH)
- [ ] 🇯🇵 Japanese (JA)
- [ ] 🇵🇹 Portuguese (PT)
- [ ] 🇩🇪 German (DE)
- [x] 🇰🇷 South Korean (KO)
- [x] 🇫🇷 French (FR)
- [ ] 🇹🇷 Turkish (TR)

✨ Add new translation

Anyone, who wants to add a new translation for Fiber, must follow these simple rules:

  1. The translation must fully follow the narrative, structure and style of presentation as in the main .github/README.md file.
  2. To be added to the master branch, the translation must be completely finished and double-checked.
  3. IT-specific phrases and comments in code snippets may not be translated.

Recommendations for PR description:

  • Add link to flag for your language or country (we use flag-icon-css with 4x3 format, for example, EN lang flag).
  • Add some words about tools, which you used to validate translation (like Google Translator, GitLocalize or DeepL).

✏️ Update translation, when new features are shipped

For current Fiber translators: please read the release notes of new official versions to update Fiber docs and .github/README.md file for your language!

💭 Improve/fix translation

If you find a translation error or want to improve translation, please make a fork of this repository, edit the corresponding README file in .github folder and send PR.

✍️ Translators list

Click to see translators list

🇷🇺 Russian

🇪🇸 Spanish

🇨🇳 Chinese

🇯🇵 Japanese

🇵🇹 Portuguese

🇩🇪 German

🇰🇷 South Korean

🇫🇷 French

🇹🇷 Turkish

This list will be update by Fiber authors, after merge your PR to master branch.

⚠️ Warnings about liability

  • All translations are done by volunteers, who are not indifferent to Fiber.
  • Fiber authors are not responsible for these translations, other than English, because they simply does not speak all these languages.

Congratulations!

This is the first web framework/library at Go that really like to me.

🔥 Add support or documentation for unit tests

I loved the framework. Simple and straightforward. Excellent for making microservices. However, I didn't find any support to create unit tests :(

The use of the gin framework is precisely because it allows the use of httptest as a standard, which is already well documented.

Maybe it would be nice to make a mock of the context to test the behaviors, and be able to access all the registered routes if you want to test the association between middleware, methods and routes.

🐞 static.go path wildcard support

Fiber version/commit
v1.4.0
Issue description
static.go line 36 can't support "/static/*"
Expected behavior

Steps to reproduce

Code snippet
// Check if wildcard for single files
if prefix == "" || prefix == "/" {
wildcard = true
}

   // line 76
  //  if prefix is "/*"  and in windows then generate \*\xxx\a.js
package main

func main() {

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.