40 lines
711 B
Go
40 lines
711 B
Go
package pg
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
// swagger:enum MediaType
|
|
// ENUM(
|
|
// Video = "video",
|
|
// Audio = "audio",
|
|
// Pdf = "pdf",
|
|
// )
|
|
type MediaType string
|
|
|
|
type MediaResources []MediaType
|
|
|
|
func (x *MediaResources) Scan(value interface{}) (err error) {
|
|
switch v := value.(type) {
|
|
case string:
|
|
return json.Unmarshal([]byte(v), &x)
|
|
case []byte:
|
|
return json.Unmarshal(v, &x)
|
|
case *string:
|
|
return json.Unmarshal([]byte(*v), &x)
|
|
}
|
|
return errors.New("Unknown type for ")
|
|
}
|
|
|
|
func (x MediaResources) Value() (driver.Value, error) {
|
|
return json.Marshal(x)
|
|
}
|
|
|
|
func (x MediaResources) MustValue() driver.Value {
|
|
return lo.Must(json.Marshal(x))
|
|
}
|