gofiber / fiber

⚡️ Express inspired web framework written in Go
https://gofiber.io
MIT License
33.87k stars 1.66k forks source link

💡 v3 discussion #1354

Closed Fenny closed 2 years ago

Fenny commented 3 years ago

Fiber

Dear Gophers, we think it's a good idea to start discussions regarding the v3. You are welcome to join us on discord where we created a dedicated channel to pin suggestions for the next update .

sujit-baniya commented 3 years ago

Features I'm thinking might go with v3

FEATURE 1: Include some features in gofiber client? 1) Timeout 2) Retry mechanism 3) Throttle

FEATURE 2: I think implementing global template layout also a good idea (including option to add properties to template. For e.g.

app := fiber.New(fiber.Config {
  ...
  Template: html.NewFileSystem(...),
  TemplateLayout: "layouts/main",
})

// Some fiber middleware to add properties to template
app.Use(func (c *fiber.Ctx) error {
  c.LayoutProperty("auth", "blabla")
  return c.Next()
})

// At this point, fiber would auto load view on above mentioned layout including all the properties from middleware
// It would work like it's currently working if user provide layout as 3rd param
// The properties would be available throughout the view file and layout
app.Get("/login", fiber(c *fiber.Ctx) error {
  return c.Render("views/login")
}
taichi1024 commented 3 years ago

Hope v3 app.static support embed

ReneWerner87 commented 3 years ago
Working Example ![image](https://user-images.githubusercontent.com/7063188/120783438-54afb900-c52b-11eb-8534-6faad1d37ef2.png)

static will probably not be rewritten, rather use the filesystem middleware, it currently does not work perfectly with embed, think here you can test again and possibly create a feature report, with which we give better support for embed FS in the filesystem middleware, but otherwise this is usable for now

Output of the example ![image](https://user-images.githubusercontent.com/7063188/120783728-9a6c8180-c52b-11eb-9802-6f1e6abd2dad.png)

but let's discuss this somewhere else, otherwise we will spam the v3 thread

ubearline commented 3 years ago

I want to be able to generate API interface documents automatically.

FlameMida commented 3 years ago

need more documents and examples with different language

G2G2G2G commented 3 years ago

"Suggestions for next update" The "caching properties of cookie so it's user friendly" suggested here: https://github.com/gofiber/fiber/issues/1127

micross commented 3 years ago

I want to be able to disable global layout in special handlers. For e.g.

app := fiber.New(fiber.Config {
  ...
  TemplateLayout: "layouts/main",
})

// disable global layout by passing "" to 3rd param
app.Get("/login", fiber(c *fiber.Ctx) error {
  return c.Render("login", fiber.Map{}, "")
}
hotrungnhan commented 3 years ago

im suggest that we can

sujit-baniya commented 3 years ago

@micross Isn't it working with empty string in c.Render("login", fiber.Map{}, ""). I checked the current logic and it seems it works as expected i.e. it will disable global layout by passing "" to 3rd param

https://github.com/gofiber/fiber/blob/master/ctx.go#L958-L962

micross commented 3 years ago

@sujit-baniya maybe it's a bug in jet template engine, it says 'template / could not be found'.

./views/index.jet

<h1>in index</h1>

./views/layouts/main.jet

<h1>in layout main</h1>
{{ embed() }}

app := fiber.New(fiber.Config{
    Views:       engine,
    ViewsLayout: "layouts/main",
})

app.Get("/", func(c *fiber.Ctx) error {
    return c.Render("index", fiber.Map{}, "")
})

https://github.com/gofiber/template/blob/master/jet/jet.go#L220-L229

sujit-baniya commented 3 years ago

@micross Yes it's a bug, I added a PR for above: https://github.com/gofiber/template/pull/135/files

anhnmt commented 3 years ago

v3 need to support gqlgen and jwt for gqlgen :D

Fenny commented 3 years ago

We decided to wait with v3 until Go1.18 is released in early 2022 along with generics 🥳

Keep you updated!

PS: Thanks for all the suggestions, keep them coming!

liaohongxing commented 3 years ago
  1. remove timeout middleware
  2. fiber.Client is stable and available
  3. add similar https://github.com/labstack/echo/blob/master/middleware/request_logger.go
efectn commented 3 years ago
efectn commented 3 years ago
  1. remove timeout middleware
  2. fiber.Client is stable and available
  3. add similar https://github.com/labstack/echo/blob/master/middleware/request_logger.go

I sent pr https://github.com/gofiber/contrib/pull/20 to support zap. But adding multiple logger seems better than my way. I can send PR if maintainers are OK.

ltns35 commented 3 years ago

Add support for HTTP/3 QUIC.

efectn commented 3 years ago

Split fasthttp methods as engines/fasthttp. Community can create own engine bindings like net/http. Similar to https://github.com/labstack/echo/tree/v2.2.0/engine but only fasthttp supported as builtin in fiber repo.

efectn commented 3 years ago
kokoraka commented 3 years ago

Change *fiber.Ctx into an interface so it's possible and easy to do unit test without the help of net/http/httptest.

ZQun commented 3 years ago

@efectn hi, Will the V3 version support http2?

Rayan1159 commented 3 years ago

@efectn hi, Will the V3 version support http2?

Fiber is built on fasthttp, so ask there.

efectn commented 3 years ago

@efectn hi, Will the V3 version support http2?

I don't know but i hope. That's maintainers' decision.

li1234yun commented 2 years ago

Explore more effective and efficient development mode, such as: support generic, more convenient tools, built-in OpenAPI doc etc.

Jictyvoo commented 2 years ago

Maybe we can add the possibility to create hooks to fiber app to everytime a new handler is registered. So in this way the user can make a way to generate a documenting page for their api

ansidev commented 2 years ago

How about a CLI command to list all routes? Many web frameworks support this one.

For example:

efectn commented 2 years ago
esmupamungkas commented 2 years ago

Automatic swagger documentation could be helpful for my case.

goofcc commented 2 years ago
  1. Routing mapping function to organize code structure in a more elegant way.
  2. Command line scaffolding, for example, it is convenient for newbies to create an app faster.
ad3n commented 2 years ago
  1. Support HTTP/2
  2. Support HTTP/3
  3. Automatic Swagger Documentation
  4. Circuit Breaker Middleware
efectn commented 2 years ago

split context into the req, resp and others (like next)

c.Req.GetHeaders()
c.Resp.GetHeaders()
c.Next()
balcieren commented 2 years ago

Should write with net/http for catching innovations. (While I was writing this comment, my hands trembled but I am ready for lynch.)

NorbertHauriel commented 2 years ago

An official implementation of burst limiter would be nice in v3, similar to this #486. As a separate middleware, or including it in the window limiters (if it makes more sense).

balcieren commented 2 years ago
  1. fiber.Ctx should be interface (for customize)
  2. fiber.Error's message should be interface (for multiple error messages)
  3. Renaming functions names
    fiber.App
    • Listen() --> Start()
    • ListenTLS() --> StartTLS()
    • ....
      fiber.Ctx
    • Query() --> QueryParam()
    • Param() --> PathParam()
    • Get()--> GetReqHeader() // GetRequestHeader()
    • Set() --> SetReqHeader() // SetRequestHeader()
    • ...
  4. Scheme() --> returns http or https / Protocol() --> returns HTTP/1.1 or HTTP/2.0 (for HTTP2)
  5. HTTP methods names should be write with uppercase. ( Get() --> GET(), Post() --> POST() ... )
  6. HTTP/2.0 Support
anhnmt commented 2 years ago

Support gRPC (gRPC Gateway)

igotfr commented 2 years ago

HTTP/2:

HTTP/3:

efectn commented 2 years ago
balcieren commented 2 years ago

New Router Idea instead of Group, Mount and Route

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

    app.Use("/user", UserRouter)

    app.Listen(":3000")
}

func UserRouter() *fiber.Router  {
  router := fiber.NewRouter(fiber.RouterConfig{})

  router.Get("/",func(c *fiber.Ctx) error  {
    return c.JSON("hi user")
  })

  return router
}
ReneWerner87 commented 2 years ago

Here you can create the feature request for your ideas https://github.com/gofiber/fiber/milestone/1

Preferably one report per feature or if they go in the same direction, then also grouped together. And please provide a code example for the usage in the report(not the implementation).

We will then review them and decide which ones will make it into the core and start with the implementation.

You are also welcome to help us

In the next time we will create a beta branch, which will be used for development.

taichi1024 commented 2 years ago

Suggest:

  1. Use Go1.18+【generics】refactoring
  2. Manage versions like Django https://static.djangoproject.com/img/release-roadmap.3c7ece4f31b3.png
  3. Support microservice features
xiayulu commented 2 years ago

Suggest:

  1. Login User is a very common pattern when build a web app.

I think web developers never say no to this feature.

ltns35 commented 2 years ago

Enable by default security best practices when protecting against common attacks that an API server could receive.

ReneWerner87 commented 2 years ago

Enable by default security best practices when protecting against common attacks that an API server could receive.

Good idea, can you create a feature request for this

Maybe with a list of best practices which we should apply, so that it is clearly defined and you can start with the implementation.

ltns35 commented 2 years ago

Enable by default security best practices when protecting against common attacks that an API server could receive.

Good idea, can you create a feature request for this. Maybe with a list of best practices which we should apply, so that it is clearly defined and you can start with the implementation.

@ReneWerner87 I'll look into it when I get back from vacation (next week) and do a feature request with its implementation.

gozeloglu commented 2 years ago

Features I'm thinking might go with v3

FEATURE 1: Include some features in gofiber client?

  1. Timeout
  2. Retry mechanism
  3. Throttle

FEATURE 2: I think implementing global template layout also a good idea (including option to add properties to template. For e.g.

app := fiber.New(fiber.Config {
  ...
  Template: html.NewFileSystem(...),
  TemplateLayout: "layouts/main",
})

// Some fiber middleware to add properties to template
app.Use(func (c *fiber.Ctx) error {
  c.LayoutProperty("auth", "blabla")
  return c.Next()
})

// At this point, fiber would auto load view on above mentioned layout including all the properties from middleware
// It would work like it's currently working if user provide layout as 3rd param
// The properties would be available throughout the view file and layout
app.Get("/login", fiber(c *fiber.Ctx) error {
  return c.Render("views/login")
}

I would like to add retry mechanism. It seems that nobody has been started to implement it. If you accept to add this feature to v3, I can start to implement.

ReneWerner87 commented 2 years ago

Features I'm thinking might go with v3 FEATURE 1: Include some features in gofiber client?

  1. Timeout
  2. Retry mechanism
  3. Throttle

FEATURE 2: I think implementing global template layout also a good idea (including option to add properties to template. For e.g.

app := fiber.New(fiber.Config {
  ...
  Template: html.NewFileSystem(...),
  TemplateLayout: "layouts/main",
})

// Some fiber middleware to add properties to template
app.Use(func (c *fiber.Ctx) error {
  c.LayoutProperty("auth", "blabla")
  return c.Next()
})

// At this point, fiber would auto load view on above mentioned layout including all the properties from middleware
// It would work like it's currently working if user provide layout as 3rd param
// The properties would be available throughout the view file and layout
app.Get("/login", fiber(c *fiber.Ctx) error {
  return c.Render("views/login")
}

I would like to add retry mechanism. It seems that nobody has been started to implement it. If you accept to add this feature to v3, I can start to implement.

Sounds good, can you first create a feature report for it

unfortunately we have currently a little start issues

we first have to create the base for the start -> when this is done we will inform in the feature reports, so you can start then

tristanisham commented 2 years ago

Add built-in type references for func(c *fiber.CTX) error called Route for clarity.

efectn commented 2 years ago

Open issues for new suggestions/features about v3.

smitpatelx commented 1 year ago

I want to be able to generate API interface documents automatically.

You can use go-swagger to generate swagger.json. Then, just use openapi-typescript-codegen in your front-end. After that just add this script:

// package.json
"scripts": {
   "gen:types": "openapi --input http://host:port/openapi.json --output ./src/generated --client axios --indent 2 --useOptions",
 }

You can change the params, refer docs for more information. It will generate types and a client you can consume via tanstack-query or server components.