product.go 751 B

123456789101112131415161718192021222324252627282930313233
  1. // product is a abstract define of same devices made by some vendor
  2. package models
  3. import (
  4. "errors"
  5. "github.com/jinzhu/gorm"
  6. )
  7. // Product product
  8. type Product struct {
  9. gorm.Model
  10. // which vendor
  11. VendorID int32
  12. // name
  13. ProductName string `sql:"type:varchar(200);not null;" binding:"required"`
  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. Devices []Device
  21. }
  22. // Validate 验证
  23. func (a *Product) Validate() error {
  24. if a.ProductName == "" || a.VendorID == 0 {
  25. return errors.New("非法参数:[ProductName, VendorID]")
  26. }
  27. return nil
  28. }