1234567891011121314151617181920212223242526272829 |
- package models
- import (
- "errors"
- "github.com/jinzhu/gorm"
- )
- // Sensor 传感器
- type Sensor struct {
- gorm.Model
- RecordId string `gorm:"column:record_id;size:32;index"`
- Name string `gorm:"size:30;not null;"` //名称
- Label uint // 标签
- ProductID uint //所属产品
- }
- // Validate 验证
- func (a *Sensor) Validate() error {
- if a.Name == "" {
- return errors.New("非法参数[Name]")
- } else if a.Label < 1 {
- return errors.New("编号不能小于1")
- } else if a.Label > 255 {
- return errors.New("编号不能大于255")
- } else if a.ProductID == 0 {
- return errors.New("缺少产品信息")
- }
- return nil
- }
|