com.snow.auto_monitor/app/http/entities/test.go

43 lines
1.7 KiB
Go
Raw Normal View History

2024-07-12 18:11:21 +08:00
package entities
//请求数据结构
type TestRequest struct {
Name string `json:"name" example:"snow"`
Url string `json:"url" example:"github.com/qit-team/snow"`
}
//返回数据结构
type TestResponse struct {
Id int64 `json:"id" example:"1"`
Name string `json:"name" example:"snow"`
Url string `json:"url" example:"github.com/qit-team/snow"`
}
/*
* validator.v9文档
* 地址https://godoc.org/gopkg.in/go-playground/validator.v9
* 列了几个大家可能会用到的如有遗漏请看上面文档
*/
//请求数据结构
type TestValidatorRequest struct {
//tips因为组件required不管是没传值或者传 0 or "" 都通过不了但是如果用指针类型那么0就是0而nil无法通过校验
Id *int64 `json:"id" validate:"required" example:"1"`
Age int `json:"age" validate:"required,gte=0,lte=130" example:"20"`
Name *string `json:"name" validate:"required" example:"snow"`
Email string `json:"email" validate:"required,email" example:"snow@github.com"`
Url string `json:"url" validate:"required" example:"github.com/qit-team/snow"`
Mobile string `json:"mobile" validate:"required" example:"snow"`
RangeNum int `json:"range_num" validate:"max=10,min=1" example:"3"`
TestNum *int `json:"test_num" validate:"required,oneof=5 7 9" example:"7"`
Content *string `json:"content" example:"snow"`
Addresses []*Address `json:"addresses" validate:"required,dive,required" `
}
// Address houses a users address information
type Address struct {
Street string `json:"street" validate:"required" example:"huandaodonglu"`
City string `json:"city" validate:"required" example:"xiamen"`
Planet string `json:"planet" validate:"required" example:"snow"`
Phone string `json:"phone" validate:"required" example:"snow"`
}