product.go 896 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Product product
  7. // product is a abstract define of same devices made by some vendor
  8. type Product struct {
  9. gorm.Model
  10. RecordId string `gorm:"primary_key;column:record_id;size:32;index"`
  11. // which vendor
  12. VendorID string `gorm:"column:vendor_id;size:32;index"`
  13. // name
  14. ProductName string `sql:"type:varchar(200);not null;"`
  15. // desc
  16. ProductDescription string `sql:"type:text;not null;"`
  17. // product key to auth a product
  18. ProductKey string `sql:"type:varchar(200);not null;unique;key;"`
  19. // product config string (JSON)
  20. ProductConfig string `sql:"type:text; not null;"`
  21. // icon of product
  22. ProductImage string
  23. // product class
  24. ProductType string
  25. Devices []Device
  26. }
  27. // Validate 验证
  28. func (a *Product) Validate() error {
  29. if a.ProductName == "" {
  30. return errors.New("非法参数:[ProductName]")
  31. }
  32. return nil
  33. }