protocal.go 831 B

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