feat: 自动字段注入支持解析二级匿名字段

This commit is contained in:
2025-10-31 14:51:00 +08:00
parent 463523f0b8
commit 2deff38f9d
4 changed files with 72 additions and 23 deletions

View File

@ -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
}