// product is a abstract define of same devices made by some vendor package models import ( "errors" "github.com/jinzhu/gorm" ) // Product product type Product struct { gorm.Model // which vendor VendorID int32 // name ProductName string `sql:"type:varchar(200);not null;" binding:"required"` // desc ProductDescription string `sql:"type:text;not null;"` // product key to auth a product ProductKey string `sql:"type:varchar(200);not null;unique;key;"` // product config string (JSON) ProductConfig string `sql:"type:text; not null;"` Devices []Device } // Validate 验证 func (a *Product) Validate() error { if a.ProductName == "" || a.VendorID == 0 { return errors.New("非法参数:[ProductName, VendorID]") } return nil }