Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route naming feature. #1650

Merged
merged 6 commits into from Dec 28, 2021
Merged

Conversation

efectn
Copy link
Member

@efectn efectn commented Dec 10, 2021

Set route name by last created route or group.

Example Use:

Code:

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

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

	app.Get("/doe", func(c *fiber.Ctx) error { 
		...
	}).Name("homgfgfe")

	app.Trace("/tracer", func(c *fiber.Ctx) error {
		...
	}).Name("tracert")

	app.Delete("/delete", func(c *fiber.Ctx) error {
		...
	}).Name("delete")

	a := app.Group("/a")
	a.Name("fd.")

	a.Get("/test", func(c *fiber.Ctx) error {
		...
	}).Name("test")

	data, _ := json.MarshalIndent(app.Stack(), "", "  ")
	fmt.Print(string(data))

	app.Listen("localhost:8080")

}

Output:

[
  [
    {
      "method": "GET",
      "name": "index",
      "path": "/",
      "params": null
    },
    {
      "method": "GET",
      "name": "homgfgfe",
      "path": "/doe",
      "params": null
    },
    {
      "method": "GET",
      "name": "fd.test",
      "path": "/a/test",
      "params": null
    }
  ],
  [
    {
      "method": "HEAD",
      "name": "",
      "path": "/",
      "params": null
    },
    {
      "method": "HEAD",
      "name": "",
      "path": "/doe",
      "params": null
    },
    {
      "method": "HEAD",
      "name": "",
      "path": "/a/test",
      "params": null
    }
  ],
  null,
  null,
  [
    {
      "method": "DELETE",
      "name": "delete",
      "path": "/delete",
      "params": null
    }
  ],
  null,
  null,
  [
    {
      "method": "TRACE",
      "name": "tracert",
      "path": "/tracer",
      "params": null
    }
  ],
  null
]

@ReneWerner87
Copy link
Member

ReneWerner87 commented Dec 10, 2021

Interesting

Can you check the tests, the last run is not successful

@efectn
Copy link
Member Author

efectn commented Dec 10, 2021

@ReneWerner87 do you know why parallel tests cause errors?

@hi019
Copy link
Member

hi019 commented Dec 11, 2021

Instead of .RouteName, I think .Name would suffice

@efectn
Copy link
Member Author

efectn commented Dec 11, 2021

Instead of .RouteName, I think .Name would suffice

Right. I'll change it today

@efectn
Copy link
Member Author

efectn commented Dec 11, 2021

Interesting

Can you check the tests, the last run is not successful

fixed

@ReneWerner87
Copy link
Member

ReneWerner87 commented Dec 17, 2021

its looking good, can you add some documentation in the readme and doc repository

@efectn
Copy link
Member Author

efectn commented Dec 17, 2021

its looking good, can you add some documentation in the readme and doc repository

What should i add in README? As feature?

efectn added a commit to efectn-forks/docs that referenced this issue Dec 18, 2021
@ReneWerner87
Copy link
Member

ReneWerner87 commented Dec 18, 2021

Yes please

efectn added a commit to efectn-forks/docs that referenced this issue Dec 18, 2021
@balcieren
Copy link
Member

balcieren commented Dec 18, 2021

@efectn will it work like

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

        app.Get("/user",func(c *fiber.Ctx) error {...}).Name("user").Get("/projects",func(c *fiber.Ctx)error {...}).Name("projects")

	app.Listen("localhost:8080")
}

@efectn
Copy link
Member Author

efectn commented Dec 18, 2021

@efectn will it work like

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

        app.Get("/user",func(c *fiber.Ctx) error {...}).Name("user").Get("/projects",func(c *fiber.Ctx)error {...}).Name("projects")

	app.Listen("localhost:8080")
}

Yeah it will work

@balcieren
Copy link
Member

balcieren commented Dec 18, 2021

@efectn will it work like

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

        app.Get("/user",func(c *fiber.Ctx) error {...}).Name("user").Get("/projects",func(c *fiber.Ctx)error {...}).Name("projects")

	app.Listen("localhost:8080")
}

Yeah it will work

👍

@ReneWerner87 ReneWerner87 merged commit 68d3b77 into gofiber:master Dec 28, 2021
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants