product.go 748 B

12345678910111213141516171819202122232425262728293031323334
  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. // which vendor
  11. VendorID int32
  12. // name
  13. ProductName string `sql:"type:varchar(200);not null;"`
  14. // desc
  15. ProductDescription string `sql:"type:text;not null;"`
  16. // product key to auth a product
  17. ProductKey string `sql:"type:varchar(200);not null;unique;key;"`
  18. // product config string (JSON)
  19. ProductConfig string `sql:"type:text; not null;"`
  20. // icon of product
  21. ProductImage string
  22. Devices []Device
  23. }
  24. // Validate 验证
  25. func (a *Product) Validate() error {
  26. if a.ProductName == "" {
  27. return errors.New("非法参数:[ProductName]")
  28. }
  29. return nil
  30. }