Skip to content

Separate param binding from param validation #4624

@bblack

Description

@bblack

Feature Description

In my gin application, we have endpoints that depend on parameters located in more than one place: e.g. in the uri (POST /org/:id/user) and the body, assumed to be json. I'd like to bind those to a single go struct, like

type GetUsersParams {
  orgId int
  name string
  role string
}

I want to be able to populate this single params struct with a single function call, looking for params in both URI and body (as json), regardless of whether each param is found in one place or the other, and assuming json regardless of whether the client passed content-type.

Unfortunately, we can't simply call shouldBindURI then shouldBindJSON, because each of those will return an error if ANY of the required GetUsersParams are absent from that particular location.

If I could call versions of these functions simply didn't call validate as their last step, and then called validate myself once at the end, this would be simple.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/proposalGot an idea for a feature that Gin doesn't have currently? Submit your idea here!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions