shipping_goods.go
884 字节
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type ShippingGoodsCommand struct {
// 订单ID
OrderId int `json:"orderId" valid:"Required"`
// 发货单号
DeliveryCode string `json:"deliveryCode" valid:"Required"`
// 订单编号
OrderNo string `json:"orderNo" valid:"Required"`
// 订单数量
OrderNum int64 `json:"orderNum" valid:"Required"`
}
func (shippingGoodsCommand *ShippingGoodsCommand) Valid(validation *validation.Validation) {
//_ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (shippingGoodsCommand *ShippingGoodsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(shippingGoodsCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}