// Code generated by go-enum DO NOT EDIT. // Version: - // Revision: - // Build Date: - // Built By: - package consts import ( "database/sql/driver" "errors" "fmt" "strings" ) const ( // CtxKeyTx is a CtxKey of type Tx. CtxKeyTx CtxKey = "__ctx_db:" // CtxKeyJwt is a CtxKey of type Jwt. CtxKeyJwt CtxKey = "__jwt_token:" // CtxKeyClaim is a CtxKey of type Claim. CtxKeyClaim CtxKey = "__jwt_claim:" ) var ErrInvalidCtxKey = fmt.Errorf("not a valid CtxKey, try [%s]", strings.Join(_CtxKeyNames, ", ")) var _CtxKeyNames = []string{ string(CtxKeyTx), string(CtxKeyJwt), string(CtxKeyClaim), } // CtxKeyNames returns a list of possible string values of CtxKey. func CtxKeyNames() []string { tmp := make([]string, len(_CtxKeyNames)) copy(tmp, _CtxKeyNames) return tmp } // CtxKeyValues returns a list of the values for CtxKey func CtxKeyValues() []CtxKey { return []CtxKey{ CtxKeyTx, CtxKeyJwt, CtxKeyClaim, } } // String implements the Stringer interface. func (x CtxKey) 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 CtxKey) IsValid() bool { _, err := ParseCtxKey(string(x)) return err == nil } var _CtxKeyValue = map[string]CtxKey{ "__ctx_db:": CtxKeyTx, "__jwt_token:": CtxKeyJwt, "__jwt_claim:": CtxKeyClaim, } // ParseCtxKey attempts to convert a string to a CtxKey. func ParseCtxKey(name string) (CtxKey, error) { if x, ok := _CtxKeyValue[name]; ok { return x, nil } return CtxKey(""), fmt.Errorf("%s is %w", name, ErrInvalidCtxKey) } var errCtxKeyNilPtr = errors.New("value pointer is nil") // one per type for package clashes // Scan implements the Scanner interface. func (x *CtxKey) Scan(value interface{}) (err error) { if value == nil { *x = CtxKey("") 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 = ParseCtxKey(v) case []byte: *x, err = ParseCtxKey(string(v)) case CtxKey: *x = v case *CtxKey: if v == nil { return errCtxKeyNilPtr } *x = *v case *string: if v == nil { return errCtxKeyNilPtr } *x, err = ParseCtxKey(*v) default: return errors.New("invalid type for CtxKey") } return } // Value implements the driver Valuer interface. func (x CtxKey) Value() (driver.Value, error) { return x.String(), nil } // Set implements the Golang flag.Value interface func. func (x *CtxKey) Set(val string) error { v, err := ParseCtxKey(val) *x = v return err } // Get implements the Golang flag.Getter interface func. func (x *CtxKey) Get() interface{} { return *x } // Type implements the github.com/spf13/pFlag Value interface. func (x *CtxKey) Type() string { return "CtxKey" } type NullCtxKey struct { CtxKey CtxKey Valid bool } func NewNullCtxKey(val interface{}) (x NullCtxKey) { 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 *NullCtxKey) Scan(value interface{}) (err error) { if value == nil { x.CtxKey, x.Valid = CtxKey(""), false return } err = x.CtxKey.Scan(value) x.Valid = (err == nil) return } // Value implements the driver Valuer interface. func (x NullCtxKey) Value() (driver.Value, error) { if !x.Valid { return nil, nil } // driver.Value accepts int64 for int values. return string(x.CtxKey), nil } type NullCtxKeyStr struct { NullCtxKey } func NewNullCtxKeyStr(val interface{}) (x NullCtxKeyStr) { x.Scan(val) // yes, we ignore this error, it will just be an invalid value. return } // Value implements the driver Valuer interface. func (x NullCtxKeyStr) Value() (driver.Value, error) { if !x.Valid { return nil, nil } return x.CtxKey.String(), nil }