product.go 766 B

1234567891011121314151617181920212223242526272829303132333435
  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. ProductType int
  23. Devices []Device
  24. }
  25. // Validate 验证
  26. func (a *Product) Validate() error {
  27. if a.ProductName == "" {
  28. return errors.New("非法参数:[ProductName]")
  29. }
  30. return nil
  31. }