Files
mp-qvyun/backend/pkg/pg/users.gen.go
2024-12-10 14:50:50 +08:00

180 lines
4.2 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 (
// BalanceTypeCharge is a BalanceType of type Charge.
BalanceTypeCharge BalanceType = "charge"
// BalanceTypeConsume is a BalanceType of type Consume.
BalanceTypeConsume BalanceType = "consume"
// BalanceTypeRefund is a BalanceType of type Refund.
BalanceTypeRefund BalanceType = "refund"
)
var ErrInvalidBalanceType = fmt.Errorf("not a valid BalanceType, try [%s]", strings.Join(_BalanceTypeNames, ", "))
var _BalanceTypeNames = []string{
string(BalanceTypeCharge),
string(BalanceTypeConsume),
string(BalanceTypeRefund),
}
// BalanceTypeNames returns a list of possible string values of BalanceType.
func BalanceTypeNames() []string {
tmp := make([]string, len(_BalanceTypeNames))
copy(tmp, _BalanceTypeNames)
return tmp
}
// BalanceTypeValues returns a list of the values for BalanceType
func BalanceTypeValues() []BalanceType {
return []BalanceType{
BalanceTypeCharge,
BalanceTypeConsume,
BalanceTypeRefund,
}
}
// String implements the Stringer interface.
func (x BalanceType) 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 BalanceType) IsValid() bool {
_, err := ParseBalanceType(string(x))
return err == nil
}
var _BalanceTypeValue = map[string]BalanceType{
"charge": BalanceTypeCharge,
"consume": BalanceTypeConsume,
"refund": BalanceTypeRefund,
}
// ParseBalanceType attempts to convert a string to a BalanceType.
func ParseBalanceType(name string) (BalanceType, error) {
if x, ok := _BalanceTypeValue[name]; ok {
return x, nil
}
return BalanceType(""), fmt.Errorf("%s is %w", name, ErrInvalidBalanceType)
}
var errBalanceTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *BalanceType) Scan(value interface{}) (err error) {
if value == nil {
*x = BalanceType("")
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 = ParseBalanceType(v)
case []byte:
*x, err = ParseBalanceType(string(v))
case BalanceType:
*x = v
case *BalanceType:
if v == nil {
return errBalanceTypeNilPtr
}
*x = *v
case *string:
if v == nil {
return errBalanceTypeNilPtr
}
*x, err = ParseBalanceType(*v)
default:
return errors.New("invalid type for BalanceType")
}
return
}
// Value implements the driver Valuer interface.
func (x BalanceType) Value() (driver.Value, error) {
return x.String(), nil
}
// Set implements the Golang flag.Value interface func.
func (x *BalanceType) Set(val string) error {
v, err := ParseBalanceType(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *BalanceType) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *BalanceType) Type() string {
return "BalanceType"
}
type NullBalanceType struct {
BalanceType BalanceType
Valid bool
}
func NewNullBalanceType(val interface{}) (x NullBalanceType) {
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 *NullBalanceType) Scan(value interface{}) (err error) {
if value == nil {
x.BalanceType, x.Valid = BalanceType(""), false
return
}
err = x.BalanceType.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullBalanceType) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return string(x.BalanceType), nil
}
type NullBalanceTypeStr struct {
NullBalanceType
}
func NewNullBalanceTypeStr(val interface{}) (x NullBalanceTypeStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullBalanceTypeStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.BalanceType.String(), nil
}