shipping.go 788 字节
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
)

type ShippingCommand struct {
	// 发货单号
	DeliveryCode string `json:"deliveryCode" valid:"Required"`
	// 订单编号
	OrderNo string `json:"orderNo" valid:"Required"`
	// 订单数量
	OrderNum int64 `json:"orderNum" valid:"Required"`
}

func (shippingCommand *ShippingCommand) Valid(validation *validation.Validation) {
	validation.SetError("CustomValid", "未实现的自定义认证")
}

func (shippingCommand *ShippingCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(shippingCommand)
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}