Skip to content

Is it possible to bind query/form multi name(alias)? #2317

Answered by aldas
yinheli asked this question in Q&A
Discussion options

You must be logged in to vote

Bind itself does not have that feature, but you could add additional code to do the same

type Node struct {
    Name string `json:"name" query:"name"`
}
n := Node{}
if err := c.Bind(&n); err != nil {
    return err
}
err := echo.QueryParamsBinder(c).
    // String("name", &n.Name).  // <-- not needed as Bind knows that from struct tag
    String("n", &n.Name).
    String("code", &n.Name).
    BindError()
if err != nil {
    return err
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@yinheli
Comment options

@aldas
Comment options

Answer selected by yinheli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants