Thanks to visit codestin.com
Credit goes to github.com

Skip to content

✨ v3 (feature): convert fiber.Ctx type to interface#1928

Merged
ReneWerner87 merged 7 commits intov3-betafrom
v3-ctx-interface
Jul 13, 2022
Merged

✨ v3 (feature): convert fiber.Ctx type to interface#1928
ReneWerner87 merged 7 commits intov3-betafrom
v3-ctx-interface

Conversation

@efectn
Copy link
Member

@efectn efectn commented Jun 2, 2022

Now we can customize ctx methods as we want. Also much helper methods for ctx were added into the ctx and app.

Inspired by: Echo v5
Closes: #1824

Example:

type customCtx struct {
	fiber.DefaultCtx
}

func (c *customCtx) Params(key string, defaultValue ...string) string {
	return "prefix_" + c.DefaultCtx.Params(key)
}

app.NewCtxFunc(func(app *fiber.App) fiber.CustomCtx {
	return &customCtx{
		DefaultCtx: *fiber.NewDefaultCtx(app),
	}
})

// id = 1
app.Get("/:id", func(c fiber.Ctx) error {
	return c.SendString(c.Params("id")) // example: prefix_1
})

@efectn efectn linked an issue Jun 2, 2022 that may be closed by this pull request
@efectn efectn changed the title ✨ v3: convert fiber.Ctx type to interface ✨ v3 (feature): convert fiber.Ctx type to interface Jun 2, 2022
@efectn efectn added this to the v3 milestone Jun 4, 2022
@efectn efectn requested a review from ReneWerner87 June 29, 2022 18:11
@ReneWerner87 ReneWerner87 merged commit a458bd3 into v3-beta Jul 13, 2022
@efectn efectn deleted the v3-ctx-interface branch July 13, 2022 07:52
@efectn efectn mentioned this pull request Jul 26, 2022
9 tasks
@efectn efectn restored the v3-ctx-interface branch August 7, 2022 09:41
@efectn efectn deleted the v3-ctx-interface branch August 7, 2022 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🚀 v3 Request: fiber.Ctx type of interface

2 participants