248 lines
5.7 KiB
Go
248 lines
5.7 KiB
Go
// Code generated by go-enum DO NOT EDIT.
|
|
// Version: -
|
|
// Revision: -
|
|
// Build Date: -
|
|
// Built By: -
|
|
|
|
package fields
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// StorageTypeLocal is a StorageType of type Local.
|
|
StorageTypeLocal StorageType = iota
|
|
// StorageTypeAliOSS is a StorageType of type AliOSS.
|
|
StorageTypeAliOSS
|
|
// StorageTypeS3 is a StorageType of type S3.
|
|
StorageTypeS3
|
|
// StorageTypeMinIO is a StorageType of type MinIO.
|
|
StorageTypeMinIO
|
|
)
|
|
|
|
var ErrInvalidStorageType = fmt.Errorf("not a valid StorageType, try [%s]", strings.Join(_StorageTypeNames, ", "))
|
|
|
|
const _StorageTypeName = "LocalAliOSSS3MinIO"
|
|
|
|
var _StorageTypeNames = []string{
|
|
_StorageTypeName[0:5],
|
|
_StorageTypeName[5:11],
|
|
_StorageTypeName[11:13],
|
|
_StorageTypeName[13:18],
|
|
}
|
|
|
|
// StorageTypeNames returns a list of possible string values of StorageType.
|
|
func StorageTypeNames() []string {
|
|
tmp := make([]string, len(_StorageTypeNames))
|
|
copy(tmp, _StorageTypeNames)
|
|
return tmp
|
|
}
|
|
|
|
// StorageTypeValues returns a list of the values for StorageType
|
|
func StorageTypeValues() []StorageType {
|
|
return []StorageType{
|
|
StorageTypeLocal,
|
|
StorageTypeAliOSS,
|
|
StorageTypeS3,
|
|
StorageTypeMinIO,
|
|
}
|
|
}
|
|
|
|
var _StorageTypeMap = map[StorageType]string{
|
|
StorageTypeLocal: _StorageTypeName[0:5],
|
|
StorageTypeAliOSS: _StorageTypeName[5:11],
|
|
StorageTypeS3: _StorageTypeName[11:13],
|
|
StorageTypeMinIO: _StorageTypeName[13:18],
|
|
}
|
|
|
|
// String implements the Stringer interface.
|
|
func (x StorageType) String() string {
|
|
if str, ok := _StorageTypeMap[x]; ok {
|
|
return str
|
|
}
|
|
return fmt.Sprintf("StorageType(%d)", x)
|
|
}
|
|
|
|
// IsValid provides a quick way to determine if the typed value is
|
|
// part of the allowed enumerated values
|
|
func (x StorageType) IsValid() bool {
|
|
_, ok := _StorageTypeMap[x]
|
|
return ok
|
|
}
|
|
|
|
var _StorageTypeValue = map[string]StorageType{
|
|
_StorageTypeName[0:5]: StorageTypeLocal,
|
|
_StorageTypeName[5:11]: StorageTypeAliOSS,
|
|
_StorageTypeName[11:13]: StorageTypeS3,
|
|
_StorageTypeName[13:18]: StorageTypeMinIO,
|
|
}
|
|
|
|
// ParseStorageType attempts to convert a string to a StorageType.
|
|
func ParseStorageType(name string) (StorageType, error) {
|
|
if x, ok := _StorageTypeValue[name]; ok {
|
|
return x, nil
|
|
}
|
|
return StorageType(0), fmt.Errorf("%s is %w", name, ErrInvalidStorageType)
|
|
}
|
|
|
|
var errStorageTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *StorageType) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
*x = StorageType(0)
|
|
return
|
|
}
|
|
|
|
// A wider range of scannable types.
|
|
// driver.Value values at the top of the list for expediency
|
|
switch v := value.(type) {
|
|
case int64:
|
|
*x = StorageType(v)
|
|
case string:
|
|
*x, err = ParseStorageType(v)
|
|
if err != nil {
|
|
// try parsing the integer value as a string
|
|
if val, verr := strconv.Atoi(v); verr == nil {
|
|
*x, err = StorageType(val), nil
|
|
}
|
|
}
|
|
case []byte:
|
|
*x, err = ParseStorageType(string(v))
|
|
if err != nil {
|
|
// try parsing the integer value as a string
|
|
if val, verr := strconv.Atoi(string(v)); verr == nil {
|
|
*x, err = StorageType(val), nil
|
|
}
|
|
}
|
|
case StorageType:
|
|
*x = v
|
|
case int:
|
|
*x = StorageType(v)
|
|
case *StorageType:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = *v
|
|
case uint:
|
|
*x = StorageType(v)
|
|
case uint64:
|
|
*x = StorageType(v)
|
|
case *int:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = StorageType(*v)
|
|
case *int64:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = StorageType(*v)
|
|
case float64: // json marshals everything as a float64 if it's a number
|
|
*x = StorageType(v)
|
|
case *float64: // json marshals everything as a float64 if it's a number
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = StorageType(*v)
|
|
case *uint:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = StorageType(*v)
|
|
case *uint64:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x = StorageType(*v)
|
|
case *string:
|
|
if v == nil {
|
|
return errStorageTypeNilPtr
|
|
}
|
|
*x, err = ParseStorageType(*v)
|
|
if err != nil {
|
|
// try parsing the integer value as a string
|
|
if val, verr := strconv.Atoi(*v); verr == nil {
|
|
*x, err = StorageType(val), nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x StorageType) Value() (driver.Value, error) {
|
|
return int64(x), nil
|
|
}
|
|
|
|
// Set implements the Golang flag.Value interface func.
|
|
func (x *StorageType) Set(val string) error {
|
|
v, err := ParseStorageType(val)
|
|
*x = v
|
|
return err
|
|
}
|
|
|
|
// Get implements the Golang flag.Getter interface func.
|
|
func (x *StorageType) Get() interface{} {
|
|
return *x
|
|
}
|
|
|
|
// Type implements the github.com/spf13/pFlag Value interface.
|
|
func (x *StorageType) Type() string {
|
|
return "StorageType"
|
|
}
|
|
|
|
type NullStorageType struct {
|
|
StorageType StorageType
|
|
Valid bool
|
|
}
|
|
|
|
func NewNullStorageType(val interface{}) (x NullStorageType) {
|
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
return
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *NullStorageType) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
x.StorageType, x.Valid = StorageType(0), false
|
|
return
|
|
}
|
|
|
|
err = x.StorageType.Scan(value)
|
|
x.Valid = (err == nil)
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullStorageType) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
// driver.Value accepts int64 for int values.
|
|
return int64(x.StorageType), nil
|
|
}
|
|
|
|
type NullStorageTypeStr struct {
|
|
NullStorageType
|
|
}
|
|
|
|
func NewNullStorageTypeStr(val interface{}) (x NullStorageTypeStr) {
|
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullStorageTypeStr) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
return x.StorageType.String(), nil
|
|
}
|