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

Deserialize path param to int #377

Closed
EwenQuim opened this issue Jan 29, 2025 · 2 comments · Fixed by #381
Closed

Deserialize path param to int #377

EwenQuim opened this issue Jan 29, 2025 · 2 comments · Fixed by #381
Assignees
Labels
feature-request New feature or request good first issue Good for newcomers
Milestone

Comments

@EwenQuim
Copy link
Member

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

It's not convenient to write

id, err := strconv.Atoi(c.PathParam("id"))
if err != nil {
    return nil, fuego.BadRequestError{
        Title:  "Invalid ID",
        Detail: "The provided ID is not a valid integer.",
        Err:    err,
    }
}

see #372 (comment)

Describe the solution you'd like

From a user POV, we want 2 more functions in the context:

  • PathParamInt(name string) int
  • PathParamIntErr(name string) (int, error)

They will be used like this:

id := c.PathParamInt("id")

// or 

id, err := c.PathParamIntErr("id")
if err != nil {
    return nil, err
}

Additional context

Please add

  • signature in ContextWithBody
  • implementation for
    • netHttpContext
    • ginContext
    • echoContext

Please mimic (and mutualise if it can be done nicely) what is done for QueryParamInt

@dylanhitt should we add uint to handle case between max Int and max Uint, or is it too niche?

@EwenQuim EwenQuim added feature-request New feature or request good first issue Good for newcomers labels Jan 29, 2025
@EwenQuim EwenQuim added this to the v0.19 milestone Jan 29, 2025
@thezbm
Copy link
Contributor

thezbm commented Jan 30, 2025

Can I be assigned to this? I'd love to give it a go.

@EwenQuim
Copy link
Member Author

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants