Documentation ¶
Index ¶
- Variables
- func ErrorCodeNames() []string
- type ErrorCode
- func (x ErrorCode) CamelCase() string
- func (x ErrorCode) Code() int
- func (x ErrorCode) CommandCase() string
- func (x ErrorCode) Description() string
- func (x ErrorCode) DottedCase() string
- func (x ErrorCode) Error() string
- func (x ErrorCode) ExportRef() string
- func (x ErrorCode) ExportType() string
- func (x *ErrorCode) Get() interface{}
- func (x ErrorCode) ID() string
- func (x ErrorCode) MarshalCSV() ([]byte, error)
- func (x ErrorCode) MarshalJSON() ([]byte, error)
- func (x ErrorCode) MarshalText() ([]byte, error)
- func (x ErrorCode) MarshalYAML() (interface{}, error)
- func (x ErrorCode) Message() string
- func (x ErrorCode) Name() string
- func (x ErrorCode) Namespace() string
- func (x ErrorCode) PackageName() string
- func (x ErrorCode) PackagePath() string
- func (x ErrorCode) PascalCase() string
- func (x ErrorCode) Path() string
- func (x *ErrorCode) Scan(value interface{}) error
- func (x ErrorCode) ScreamingCase() string
- func (x *ErrorCode) Set(val string) error
- func (x ErrorCode) SnakeCase() string
- func (x ErrorCode) String() string
- func (x ErrorCode) TrainCase() string
- func (x ErrorCode) Type() string
- func (x *ErrorCode) UnmarshalCSV(b []byte) error
- func (x *ErrorCode) UnmarshalJSON(b []byte) error
- func (x *ErrorCode) UnmarshalText(text []byte) error
- func (x *ErrorCode) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (x ErrorCode) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUndefinedErrorCodeEnumValue is thrown when ParseErrorCode(s string) cannot locate a valid enum for the provided string. ErrUndefinedErrorCodeEnumValue = errors.New("cannot identify enum for provided value") )
Functions ¶
func ErrorCodeNames ¶
func ErrorCodeNames() []string
ErrorCodeNames returns a list of possible string values of ErrorCode.
Types ¶
type ErrorCode ¶
type ErrorCode int
ErrorCode is a generated type alias for the ErrorCode enum. ErrorCode is an example error type that is used to demonstrate how renum's enum generator works.
const ( // ErrorCodeUndefinedEnumValue is an enum value for type ErrorCode. // ErrorCodeUndefinedEnumValue is the default value for enum type ErrorCode. It is meant to be a place holder and default for unknown values. ErrorCodeUndefinedEnumValue ErrorCode = iota // Unauthorized is thrown when the request action cannot be taken. // Unauthorized is thrown to signify that the request was made by an *authenticated* requester, but that requester is not authorized to perform the requested action. ErrorCodeUnauthorized // ErrorCodeInvalidSQLQuery is an enum value for type ErrorCode. // InvalidSQLQuery is thrown when a user supplied SQL query is not valid. // InvalidSQLQuery often means the caller should perform further validation in order to locate situations where they're taking unsanitized input from users and interpolating that value directly into the SQL query. ErrorCodeInvalidSQLQuery )
func ErrorCodeValues ¶
func ErrorCodeValues() []ErrorCode
ErrorCodeValues returns a list of possible enum values for the ErrorCode type.
func LookupErrorCode ¶
LookupErrorCode attempts to convert a int to it's equivelent ErrorCode value.
func ParseErrorCode ¶
ParseErrorCode attempts to convert a string identifier to it's corrasponding ErrorCode value, returning an error if it cannot match the string to a known enum value. This function supports multiple casings including: snake_case, PascalCase, camelCase, SCREAMING_CASE, and command-case. Generally, snake_case is the preferred method as most Marshalers will marshal to snake_case, and this function optimizes for it, but ParseErrorCode attempts to be flexible.
In the event ParseErrorCode cannot identify a matching value, it will return the default ErrorCode value (0) along with an ErrUndefinedErrorCodeEnumValue error. This will also be the return should you provide either an empty string or a string that doesn't contain a valid UTF-8 alpha character as the first rune in the string. There are two exceptions to this rule:
- The string has leading is whitespace in which case ParseErrorCode will detect, trim, and attempt to parse the result.
- The string is an integer, in which case it will attempt to match the ErrorCode value for that corrasponding integer.
If either of those options cannot subsequently locate a corrasponding enum value, it will return the default error behavior described above.
func (ErrorCode) Code ¶
Code implements the renum.Coder interface and allows an enum value to self report it's underlying integer ID. This primarily was intended to be able to support generic numeric types, but at this time, it's simply an int. This method implements the github.com/gen0cide/renum.Coder interface.
func (ErrorCode) CommandCase ¶
CommandCase returns the enum as a command-case string.
func (ErrorCode) Description ¶
Description allows a caller to retrieve more detailed description information about an enum value. This information is not passed around with the enum, but kept inside the source package and retrieved with this method. This method implements the github.com/gen0cide/renum.Descriptioner interface.
func (ErrorCode) DottedCase ¶
DottedCase returns the enum value as a dotted.case string.
func (ErrorCode) ExportRef ¶
ExportRef returns the full Go import path for the parent package of ErrorCode joined with the exported name for the enum value. This is part of the github.com/gen0cide/renum.Sourcer interface.
func (ErrorCode) ExportType ¶
ExportType returns package name the parent package of ErrorCode joined with the exported name for the enum value. This is part of the github.com/gen0cide/renum.Sourcer interface.
func (*ErrorCode) Get ¶
func (x *ErrorCode) Get() interface{}
Get implements the Golang flag.Getter interface and allows for the value of flag.Value to be retrieved by the flag package for various reasons.
func (ErrorCode) ID ¶
ID returns a snake_case identifier comprised of the enum's standard snake_case prefixed with the ErrorCode's snake_case name. This method implements the github.com/gen0cide/renum.Namespacer interface.
func (ErrorCode) MarshalCSV ¶
MarshalCSV implements the csvutil.Marshaler interface. (https://godoc.org/github.com/jszwec/csvutil#Marshaler)
func (ErrorCode) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (ErrorCode) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface and allows ErrorCode values to be encoded to text, supporting any format that uses encoding.TextMarshaler under the hood.
func (ErrorCode) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface.
func (ErrorCode) Name ¶
Name returns a snake case identifier comprised of the enum's actual identifier. This name essentially is an alias to the String() function.
func (ErrorCode) Namespace ¶
Namespace returns the a dotted namespace representation of the Go package import path for the parent package to ErrorCode. This method implements the github.com/gen0cide/renum.Namespacer interface.
func (ErrorCode) PackageName ¶
PackageName returns the name of the parent package for the ErrorCode type as part of the github.com/gen0cide/renum.Sourcer interface.
func (ErrorCode) PackagePath ¶
ImportPath returns the full import path of the parent package for the ErrorCode type as part of the github.com/gen0cide/renum.Sourcer interface.
func (ErrorCode) PascalCase ¶
PascalCase returns the enum as a PascalCase string.
func (ErrorCode) Path ¶
Paths returns a full "path" comprised of namespace + id for a given enum value. This method implements the github.com/gen0cide/renum.Namespacer interface.
func (*ErrorCode) Scan ¶
Scan implements the sql.Scanner interface and allows for translating database results into ErrorCode values. This does a best effort to match whatever might be returned (integer values, strings, or bytes) into a matching value, and follows the semantics of ParseErrorCode.
func (ErrorCode) ScreamingCase ¶
ScreamingCase returns the enum as a SCREAMING_CASE string.
func (*ErrorCode) Set ¶
Set implements the Golang flag.Value interface and allows command line flags that are bound to ErrorCode types to automatically support string representations for value assignment. This follows the semantics of ParseErrorCode and thus can be flexible for how the string should be cased, etc. If an appropriate value cannot be identified, it will return an error.
func (ErrorCode) Type ¶
Type implements the renum.Typer interface and allows the ErrorCode to self report the type of value it is. This method implements the github.com/gen0cide/renum.Typer interface.
func (*ErrorCode) UnmarshalCSV ¶
UnmarshalCSV implements the csvutil.Unmarshaler interface. (https://godoc.org/github.com/jszwec/csvutil#Unmarshaler)
func (*ErrorCode) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*ErrorCode) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface and allows ErrorCode values to be decoded from anything using this generic interface.
func (*ErrorCode) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.
func (ErrorCode) Value ¶
Value implements the driver.Valuer interface to enable automatic conversion of renum.Enum values into database types. By default, this is done with as a snake_case string to support as many database implementations as possible. If you wish to optimize to integers or other types, implement a wrapper type.