feat: 自动字段注入支持解析二级匿名字段
This commit is contained in:
@ -13,8 +13,28 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type testCommon struct {
|
||||
UserID uint `json:"user_id"`
|
||||
}
|
||||
|
||||
type testForm struct {
|
||||
Meta `json:"-" method:"get" path:"test"`
|
||||
testCommon
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
s := NewServer(9087)
|
||||
s.Router().GET("/ping", func(c *gin.Context) {})
|
||||
s.AddCommonParamRule("UserID", func(ctx *gin.Context) (any, error) {
|
||||
return uint(123456), nil
|
||||
})
|
||||
s.Group("", nil, testController{})
|
||||
s.Start()
|
||||
}
|
||||
|
||||
type testController struct {
|
||||
}
|
||||
|
||||
func (tc testController) Test(ctx *gin.Context, requestData *testForm) (*testCommon, error) {
|
||||
return &testCommon{UserID: requestData.UserID}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user