Skip to content

内嵌的struct中的字段的default值的问题 #318

@guihouchang

Description

@guihouchang

System (please complete the following information):

  • OS: linux
  • GO Version: 1.23
  • Pkg Version: 1.5.6

Describe the bug

当我的ListPackagesRequest内嵌了PageRequest结构体时,ListPackagesRequest的Page设置为空指针,不会自动赋值我设置的默认值

To Reproduce

// go code
type PageRequest struct {
	state protoimpl.MessageState `protogen:"open.v1"`
	// 页码

	Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty" validate:"required|int|min:1|default:1" message:"页码至少为1"`
	// 每页大小

	PageSize      int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty" validate:"required|int|max:100|default:10" message:"每页大小范围为1-100"`
	unknownFields protoimpl.UnknownFields
	sizeCache     protoimpl.SizeCache
}

type ListPackagesRequest struct {
	state protoimpl.MessageState `protogen:"open.v1"`
	// 分页参数

	Page *v11.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page,omitempty" validate:"optional" `
	// 套餐状态

	Status        PackageStatus `protobuf:"varint,2,opt,name=status,proto3,enum=api.order.v1.PackageStatus" json:"status,omitempty" validate:"optional" message:"可选的套餐状态筛选"`
	unknownFields protoimpl.UnknownFields
	sizeCache     protoimpl.SizeCache
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions