Closed
Description
Issue Description
bind the query params into target struct's anonymous filed which is a pointer to struct,
note that if the payload in http body, it seems bind works fine,
issue happens only when bind query params with a struct with an anonymous filed which is a pointer to struct
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
curl 'http://localhost:8000/test?limit=1'
{"limit":1,"offset":0}
Actual behaviour
bind skips the anonymous filed
curl 'http://localhost:8000/test?limit=1'
{"limit":0,"offset":0}
Steps to reproduce
curl 'http://localhost:8000/test?limit=1'
Working code to debug
package main
import (
"fmt"
"github.com/labstack/echo/v4"
"net/http"
)
type PaginationParas struct {
Limit int `json:"limit" query:"limit"`
Offset int `json:"offset" query:"offset"`
}
type Foo struct {
*PaginationParas
}
func main() {
e := echo.New()
e.Debug = true
e.GET("/test", func(ctx echo.Context) error {
var f = Foo{PaginationParas: &PaginationParas{}}
if err := ctx.Bind(&f); err != nil {
fmt.Println(err)
return err
}
return ctx.JSON(http.StatusOK, f)
})
e.Logger.Fatal(e.Start(":8000"))
}
Version/commit
v4.2.3-0.20210417194748-3b07058a1d8f
Metadata
Metadata
Assignees
Labels
No labels