package models import ( "errors" "github.com/jinzhu/gorm" ) type Ota struct { gorm.Model RecordId string `gorm:"column:record_id;size:32;index"` Name string `gorm:"column:name;size:100"` Url string `gorm:"column:url;size:200"` Version string `gorm:"column:version;size:20"` Size int `gorm:"column:size;"` ProductId string `gorm:"column:product_id;size:32;index;"` ProductName string `gorm:"column:product_name;size:50;"` VendorId string `gorm:"column:vendor_id;size:32;"` } // Validate 验证 func (a *Ota) Validate() error { if a.Url == "" { return errors.New("非法参数:[url]") } return nil } type OtaUpgradeParams struct { VendorId string `json:"vendor_id"` FileId string `json:"file_id"` ProductId string `json:"product_id"` DeviceIDs []string `json:"device_ids"` } // Validate 验证 func (a *OtaUpgradeParams) Validate() error { if a.FileId == "" { return errors.New("非法参数:[file_id]") } if a.ProductId == "" && len(a.DeviceIDs) == 0 { return errors.New("非法参数:[product_id,device_ids]") } return nil }