175 lines
3.7 KiB
Go
175 lines
3.7 KiB
Go
// Code generated by go-enum DO NOT EDIT.
|
|
// Version: -
|
|
// Revision: -
|
|
// Build Date: -
|
|
// Built By: -
|
|
|
|
package events
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// TopicProcessed is a Topic of type Processed.
|
|
TopicProcessed Topic = "event:processed"
|
|
// TopicUserRegister is a Topic of type UserRegister.
|
|
TopicUserRegister Topic = "user:register"
|
|
)
|
|
|
|
var ErrInvalidTopic = fmt.Errorf("not a valid Topic, try [%s]", strings.Join(_TopicNames, ", "))
|
|
|
|
var _TopicNames = []string{
|
|
string(TopicProcessed),
|
|
string(TopicUserRegister),
|
|
}
|
|
|
|
// TopicNames returns a list of possible string values of Topic.
|
|
func TopicNames() []string {
|
|
tmp := make([]string, len(_TopicNames))
|
|
copy(tmp, _TopicNames)
|
|
return tmp
|
|
}
|
|
|
|
// TopicValues returns a list of the values for Topic
|
|
func TopicValues() []Topic {
|
|
return []Topic{
|
|
TopicProcessed,
|
|
TopicUserRegister,
|
|
}
|
|
}
|
|
|
|
// String implements the Stringer interface.
|
|
func (x Topic) 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 Topic) IsValid() bool {
|
|
_, err := ParseTopic(string(x))
|
|
return err == nil
|
|
}
|
|
|
|
var _TopicValue = map[string]Topic{
|
|
"event:processed": TopicProcessed,
|
|
"user:register": TopicUserRegister,
|
|
}
|
|
|
|
// ParseTopic attempts to convert a string to a Topic.
|
|
func ParseTopic(name string) (Topic, error) {
|
|
if x, ok := _TopicValue[name]; ok {
|
|
return x, nil
|
|
}
|
|
return Topic(""), fmt.Errorf("%s is %w", name, ErrInvalidTopic)
|
|
}
|
|
|
|
var errTopicNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *Topic) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
*x = Topic("")
|
|
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 = ParseTopic(v)
|
|
case []byte:
|
|
*x, err = ParseTopic(string(v))
|
|
case Topic:
|
|
*x = v
|
|
case *Topic:
|
|
if v == nil {
|
|
return errTopicNilPtr
|
|
}
|
|
*x = *v
|
|
case *string:
|
|
if v == nil {
|
|
return errTopicNilPtr
|
|
}
|
|
*x, err = ParseTopic(*v)
|
|
default:
|
|
return errors.New("invalid type for Topic")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x Topic) Value() (driver.Value, error) {
|
|
return x.String(), nil
|
|
}
|
|
|
|
// Set implements the Golang flag.Value interface func.
|
|
func (x *Topic) Set(val string) error {
|
|
v, err := ParseTopic(val)
|
|
*x = v
|
|
return err
|
|
}
|
|
|
|
// Get implements the Golang flag.Getter interface func.
|
|
func (x *Topic) Get() interface{} {
|
|
return *x
|
|
}
|
|
|
|
// Type implements the github.com/spf13/pFlag Value interface.
|
|
func (x *Topic) Type() string {
|
|
return "Topic"
|
|
}
|
|
|
|
type NullTopic struct {
|
|
Topic Topic
|
|
Valid bool
|
|
}
|
|
|
|
func NewNullTopic(val interface{}) (x NullTopic) {
|
|
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 *NullTopic) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
x.Topic, x.Valid = Topic(""), false
|
|
return
|
|
}
|
|
|
|
err = x.Topic.Scan(value)
|
|
x.Valid = (err == nil)
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullTopic) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
// driver.Value accepts int64 for int values.
|
|
return string(x.Topic), nil
|
|
}
|
|
|
|
type NullTopicStr struct {
|
|
NullTopic
|
|
}
|
|
|
|
func NewNullTopicStr(val interface{}) (x NullTopicStr) {
|
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullTopicStr) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
return x.Topic.String(), nil
|
|
}
|