fiber
fiber copied to clipboard
✨ V3 Alpha Trial (95% inspired by Express)
Tiny Fiber 👌
Firstly, I know v3-beta
branch also I support it. But I want to try close to full Express.JS
inspired. I have done a lot of things. I will share information about "what I do", "what I will" etc. If you follow Express Doc you can give support.
-
[x] Replaced v2 with v3
-
[x] Moved some internal packages to go.mod
-
[x] Upgraded go version to 1.19
-
[x] Fixed deprecated ioutil errors
-
[X] Removed hooks.
-
[x] Added new mounting app system and fixed bugs from old version
-
[ ] Sub in sub mounting
-
[x] Added mount tests and benchmarks
-
[x] Combined
ListenTLS()
andListenMutualTLS()
onListen()
function -
[x] Updated new Listen function's tests
-
[x] Added
Host()
Context -
[x] Added
Host()
tests and benchmarks -
[x] Fixed
HostName()
function. It should be return host without port number -
[X] Updated
HostName()
function's test -
[X] Removed
Group()
andRoute()
functions -
[X] Added new fiber router system (We need better and cleaner solution for router)
-
[ ] register mounted app's router's stack
-
[x] Added app.Router (express app.router)
-
[x] Fixed not working router config
-
[ ] Improved router nested params performance
-
[x] Added router tests and benchmarks
-
[ ] Client refactor https://github.com/gofiber/fiber/pull/1986
-
[x] Added Express Route (express route)
-
[x] Added
Route()
tests and benchmarks -
[ ] Added
Render()
function to app (express render) -
[ ] Added
Render()
tests and benchmarks -
[x] Added ctx.Render callback function (express response.render' callback)
-
[x] Added ctx.Render callback test
-
[ ] Added
CookieParser()
function to Context -
[ ] Added
Param()
function to App and Router (express param) -
[x] Added back redirect feature to
Redirect()
express redirect -
[x] Fixed Context
Render()
bug -
[x] New static system
-
[ ] We can do like this express app engine for template engine
-
[x] ErrorHandler was moved to Use() function
func main() {
app := New()
app.Use(func(c *Ctx, err error) error {
return c.Status(200).SendString("hi, i'm an custom error")
})
}
- [x] Added router error handler
func main() {
app := New()
router := NewRouter()
app.Use("/router", router)
router.Use(func(c *fiber.Ctx, err error) error {
return c.Status(500).SendString("I'm router error handler")
})
}
- [x] Multi prefix for mounting, router and paths
func main() {
app := fiber.New()
router := fiber.NewRouter()
app.Use([]string{"/fiber", "/amazing"}, router)
router.Get("/", func(c *fiber.Ctx) error {
return c.JSON("fiber is amazing👌")
})
}
- [x] Nested params for router
func main() {
app := fiber.New()
router := fiber.NewRouter(fiber.RouterConfig{
MergeParams: true,
})
app.Use("/router/:id", router)
router.Get("/:name", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"id": c.Params("id"),
"name": c.Params("name"),
})
})
}
- [ ] Error Handlers according to paths
func main() {
app := New()
// This error handler is gonna work for `/fiber` path
app.Use("/fiber", func(c *Ctx, err error) error {
return c.Status(500).SendString("I'm error handler for `/fiber` path")
})
app.Get("/fiber", func(c *fiber.Ctx) error {
return fiber.NewError(500, "")
})
}
- [x] Event Emitter System instead of Hooks (inspired by express)
func main() {
app := fiber.New()
app.On("greet", func(data byte) {
///...
})
app.Get("/", func(c *fiber.Ctx) error {
c.Emit("greet", fiber.Map{
"message": "hi fiber ",
})
return c.JSON("👋")
})
app.Listen(":3000")
}
maybe we should create a v2 branch before merging v3 into master…
@Trim21 Firstly we should fix known problems for v2. We should catch stable v2 before v3 ...
maybe we should create a v2 branch before merging v3 into master…
i agree we will not transfer at this time the code to the master
first version 3 must be ready
Do we need to add some issues to track these tasks? It seems that the above features are not fully covered in the current issue.
I think this PR should have splitted into the PRs and issues that targets v3-beta
@balcieren can you create a pull request with the v3-beta target
can you create a pull request with the v3-beta target
v3-beta started to go away from inspired express. I think when express.js user came to fiber, will meet different things. A lot of different features are not meaning users will use them. When I was using express.js, everything was enough. I think fiber also should be like that. I think when we go away from express doc, we can lost a lot of users. We should decide to choose true way.
I am closing this pr, some features can add to version 3 inspiring by this pr