gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.79k stars 1.61k forks source link

The fields in the structure will not be set to default values ​​when requesting #3594

Open xixihahag opened 6 months ago

xixihahag commented 6 months ago

Go version

go version go1.21.3 darwin/amd64

GoFrame version

2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

请求 Hello 接口,没有传任何值

type HelloReq struct {
    g.Meta `path:"/hello" tags:"Hello" method:"post" summary:"You first hello api"`

    Data HelloOption `p:"data"`
    UUID string      `p:"uuid" dc:"uuid" d:"00000"`
}

type HelloOption struct {
    Option1 string `p:"option_1" d:"123123"`
}

type HelloRes struct {
    g.Meta `mime:"text/html" example:"string"`
}
image

What did you see happen?

HelloOption 结构体里面的值不会被初始化

image

What did you expect to see?

期望请求里面的值都会被设置成默认值

wln32 commented 6 months ago

对于默认值的设置,目前没有递归的检查结构体,可以把HelloOption改成匿名的结构体试试

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


For the setting of default values, there is currently no recursive checking structure. You can try changing HelloOption to an anonymous structure.