sensor.go 637 B

1234567891011121314151617181920212223242526272829
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Sensor 传感器
  7. type Sensor struct {
  8. gorm.Model
  9. RecordId string `gorm:"column:record_id;size:32;index"`
  10. Name string `gorm:"size:30;not null;"` //名称
  11. Label uint // 标签
  12. ProductID uint //所属产品
  13. }
  14. // Validate 验证
  15. func (a *Sensor) Validate() error {
  16. if a.Name == "" {
  17. return errors.New("非法参数[Name]")
  18. } else if a.Label < 1 {
  19. return errors.New("编号不能小于1")
  20. } else if a.Label > 255 {
  21. return errors.New("编号不能大于255")
  22. } else if a.ProductID == 0 {
  23. return errors.New("缺少产品信息")
  24. }
  25. return nil
  26. }