180 lines
4.0 KiB
Go
180 lines
4.0 KiB
Go
// Code generated by go-enum DO NOT EDIT.
|
|
// Version: -
|
|
// Revision: -
|
|
// Build Date: -
|
|
// Built By: -
|
|
|
|
package pg
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// MediaTypeVideo is a MediaType of type Video.
|
|
MediaTypeVideo MediaType = "video"
|
|
// MediaTypeAudio is a MediaType of type Audio.
|
|
MediaTypeAudio MediaType = "audio"
|
|
// MediaTypePdf is a MediaType of type Pdf.
|
|
MediaTypePdf MediaType = "pdf"
|
|
)
|
|
|
|
var ErrInvalidMediaType = fmt.Errorf("not a valid MediaType, try [%s]", strings.Join(_MediaTypeNames, ", "))
|
|
|
|
var _MediaTypeNames = []string{
|
|
string(MediaTypeVideo),
|
|
string(MediaTypeAudio),
|
|
string(MediaTypePdf),
|
|
}
|
|
|
|
// MediaTypeNames returns a list of possible string values of MediaType.
|
|
func MediaTypeNames() []string {
|
|
tmp := make([]string, len(_MediaTypeNames))
|
|
copy(tmp, _MediaTypeNames)
|
|
return tmp
|
|
}
|
|
|
|
// MediaTypeValues returns a list of the values for MediaType
|
|
func MediaTypeValues() []MediaType {
|
|
return []MediaType{
|
|
MediaTypeVideo,
|
|
MediaTypeAudio,
|
|
MediaTypePdf,
|
|
}
|
|
}
|
|
|
|
// String implements the Stringer interface.
|
|
func (x MediaType) String() string {
|
|
return string(x)
|
|
}
|
|
|
|
// IsValid provides a quick way to determine if the typed value is
|
|
// part of the allowed enumerated values
|
|
func (x MediaType) IsValid() bool {
|
|
_, err := ParseMediaType(string(x))
|
|
return err == nil
|
|
}
|
|
|
|
var _MediaTypeValue = map[string]MediaType{
|
|
"video": MediaTypeVideo,
|
|
"audio": MediaTypeAudio,
|
|
"pdf": MediaTypePdf,
|
|
}
|
|
|
|
// ParseMediaType attempts to convert a string to a MediaType.
|
|
func ParseMediaType(name string) (MediaType, error) {
|
|
if x, ok := _MediaTypeValue[name]; ok {
|
|
return x, nil
|
|
}
|
|
return MediaType(""), fmt.Errorf("%s is %w", name, ErrInvalidMediaType)
|
|
}
|
|
|
|
var errMediaTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *MediaType) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
*x = MediaType("")
|
|
return
|
|
}
|
|
|
|
// A wider range of scannable types.
|
|
// driver.Value values at the top of the list for expediency
|
|
switch v := value.(type) {
|
|
case string:
|
|
*x, err = ParseMediaType(v)
|
|
case []byte:
|
|
*x, err = ParseMediaType(string(v))
|
|
case MediaType:
|
|
*x = v
|
|
case *MediaType:
|
|
if v == nil {
|
|
return errMediaTypeNilPtr
|
|
}
|
|
*x = *v
|
|
case *string:
|
|
if v == nil {
|
|
return errMediaTypeNilPtr
|
|
}
|
|
*x, err = ParseMediaType(*v)
|
|
default:
|
|
return errors.New("invalid type for MediaType")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x MediaType) Value() (driver.Value, error) {
|
|
return x.String(), nil
|
|
}
|
|
|
|
// Set implements the Golang flag.Value interface func.
|
|
func (x *MediaType) Set(val string) error {
|
|
v, err := ParseMediaType(val)
|
|
*x = v
|
|
return err
|
|
}
|
|
|
|
// Get implements the Golang flag.Getter interface func.
|
|
func (x *MediaType) Get() interface{} {
|
|
return *x
|
|
}
|
|
|
|
// Type implements the github.com/spf13/pFlag Value interface.
|
|
func (x *MediaType) Type() string {
|
|
return "MediaType"
|
|
}
|
|
|
|
type NullMediaType struct {
|
|
MediaType MediaType
|
|
Valid bool
|
|
}
|
|
|
|
func NewNullMediaType(val interface{}) (x NullMediaType) {
|
|
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
_ = err // make any errcheck linters happy
|
|
return
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *NullMediaType) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
x.MediaType, x.Valid = MediaType(""), false
|
|
return
|
|
}
|
|
|
|
err = x.MediaType.Scan(value)
|
|
x.Valid = (err == nil)
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullMediaType) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
// driver.Value accepts int64 for int values.
|
|
return string(x.MediaType), nil
|
|
}
|
|
|
|
type NullMediaTypeStr struct {
|
|
NullMediaType
|
|
}
|
|
|
|
func NewNullMediaTypeStr(val interface{}) (x NullMediaTypeStr) {
|
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullMediaTypeStr) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
return x.MediaType.String(), nil
|
|
}
|