rest/types/rule.go

40 lines
825 B
Go

package types
import (
"database/sql/driver"
"encoding/json"
)
type Rule struct {
Min int `json:"min"`
Max int `json:"max"`
Type string `json:"type"`
Unique bool `json:"unique"`
Required []string `json:"required"`
Regular string `json:"regular"`
}
// Value implements the driver Valuer interface.
func (n Scenarios) Value() (driver.Value, error) {
return json.Marshal(n)
}
// Scan implements the Scanner interface.
func (n *Rule) Scan(value interface{}) error {
if value == nil {
return nil
}
switch s := value.(type) {
case string:
return json.Unmarshal([]byte(s), n)
case []byte:
return json.Unmarshal(s, n)
}
return ErrDbTypeUnsupported
}
// Value implements the driver Valuer interface.
func (n Rule) Value() (driver.Value, error) {
return json.Marshal(n)
}