gf icon indicating copy to clipboard operation
gf copied to clipboard

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

Open xixihahag opened this issue 1 year ago • 2 comments

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?

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

xixihahag avatar May 21 '24 03:05 xixihahag

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

wln32 avatar May 21 '24 08:05 wln32

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.

Issues-translate-bot avatar May 21 '24 08:05 Issues-translate-bot