protocal.go 774 B

1234567891011121314151617181920212223242526272829303132
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Protocal 产品协议(数据点)
  7. type Protocal struct {
  8. gorm.Model
  9. Name string `gorm:"size:30;not null;"` //名称
  10. Label string `gorm:"size:20;not null;"` // 标签
  11. Type int //读写类型
  12. ReadWriteType int //数据类型
  13. UnitSymbol string //单位
  14. Description string //备注
  15. ProductID uint //所属产品
  16. SensorID uint //所属传感器
  17. }
  18. // Validate 验证
  19. func (a *Protocal) Validate() error {
  20. if a.Name == "" || a.Label == "" {
  21. return errors.New("非法参数[Name, Label]")
  22. } else if a.ProductID == 0 {
  23. return errors.New("缺少产品信息")
  24. } else if a.SensorID == 0 {
  25. return errors.New("缺少传感器信息")
  26. }
  27. return nil
  28. }