1234567891011121314151617181920212223242526272829303132 |
- package models
- import (
- "errors"
- "github.com/jinzhu/gorm"
- )
- // Protocal 产品协议(数据点)
- type Protocal struct {
- gorm.Model
- Name string `gorm:"size:30;not null;"` //名称
- Label string `gorm:"size:20;not null;"` // 标签
- Type int //读写类型
- ReadWriteType int //数据类型
- UnitSymbol string //单位
- Description string //备注
- ProductID uint //所属产品
- SensorID uint //所属传感器
- }
- // Validate 验证
- func (a *Protocal) Validate() error {
- if a.Name == "" || a.Label == "" {
- return errors.New("非法参数[Name, Label]")
- } else if a.ProductID == 0 {
- return errors.New("缺少产品信息")
- } else if a.SensorID == 0 {
- return errors.New("缺少传感器信息")
- }
- return nil
- }
|