update_order.go
900 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type UpdateOrderCommand struct {
// 订单id
OrderId int64 `json:"orderId" valid:"Required"`
// 发货地址
BuyerName string `json:"buyerName"`
// 订单商品总数
OrderNum int `json:"orderNum"`
// 订单总价
TotalPrice float64 `json:"totalPrice"`
// 收货地址
ShippingAddress string `json:"shippingAddress,omitempty"`
}
func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateOrderCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}