ota.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type Ota struct {
  7. gorm.Model
  8. RecordId string `gorm:"column:record_id;size:32;index"`
  9. Name string `gorm:"column:name;size:100"`
  10. Url string `gorm:"column:url;size:200"`
  11. Version string `gorm:"column:version;size:20"`
  12. Size int `gorm:"column:size;"`
  13. ProductId string `gorm:"column:product_id;size:32;index;"`
  14. ProductName string `gorm:"column:product_name;size:50;"`
  15. VendorId string `gorm:"column:vendor_id;size:32;"`
  16. }
  17. // Validate 验证
  18. func (a *Ota) Validate() error {
  19. if a.Url == "" {
  20. return errors.New("非法参数:[url]")
  21. }
  22. return nil
  23. }
  24. type OtaUpgradeParams struct {
  25. VendorId string `json:"vendor_id"`
  26. FileId string `json:"file_id"`
  27. ProductId string `json:"product_id"`
  28. DeviceIDs []string `json:"device_ids"`
  29. }
  30. // Validate 验证
  31. func (a *OtaUpgradeParams) Validate() error {
  32. if a.FileId == "" {
  33. return errors.New("非法参数:[file_id]")
  34. }
  35. if a.ProductId == "" && len(a.DeviceIDs) == 0 {
  36. return errors.New("非法参数:[product_id,device_ids]")
  37. }
  38. return nil
  39. }