lib

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

	// ErrorCodeUnauthorized is an enum value for type ErrorCode.
	// 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

func LookupErrorCode(id int) (ErrorCode, error)

LookupErrorCode attempts to convert a int to it's equivelent ErrorCode value.

func ParseErrorCode

func ParseErrorCode(name string) (ErrorCode, error)

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) CamelCase

func (x ErrorCode) CamelCase() string

CamelCase returns the enum value as a camelCase string.

func (ErrorCode) Code

func (x ErrorCode) Code() int

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

func (x ErrorCode) CommandCase() string

CommandCase returns the enum as a command-case string.

func (ErrorCode) Description

func (x ErrorCode) Description() string

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

func (x ErrorCode) DottedCase() string

DottedCase returns the enum value as a dotted.case string.

func (ErrorCode) Error

func (x ErrorCode) Error() string

Error implements the error interface.

func (ErrorCode) ExportRef

func (x ErrorCode) ExportRef() string

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

func (x ErrorCode) ExportType() string

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

func (x ErrorCode) ID() string

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

func (x ErrorCode) MarshalCSV() ([]byte, error)

MarshalCSV implements the csvutil.Marshaler interface. (https://godoc.org/github.com/jszwec/csvutil#Marshaler)

func (ErrorCode) MarshalJSON

func (x ErrorCode) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (ErrorCode) MarshalText

func (x ErrorCode) MarshalText() ([]byte, error)

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

func (x ErrorCode) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (ErrorCode) Message

func (x ErrorCode) Message() string

Message returns the enum short message description.

func (ErrorCode) Name

func (x ErrorCode) Name() string

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

func (x ErrorCode) Namespace() string

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

func (x ErrorCode) PackageName() string

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

func (x ErrorCode) PackagePath() string

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

func (x ErrorCode) PascalCase() string

PascalCase returns the enum as a PascalCase string.

func (ErrorCode) Path

func (x ErrorCode) Path() string

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

func (x *ErrorCode) Scan(value interface{}) error

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

func (x ErrorCode) ScreamingCase() string

ScreamingCase returns the enum as a SCREAMING_CASE string.

func (*ErrorCode) Set

func (x *ErrorCode) Set(val string) error

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) SnakeCase

func (x ErrorCode) SnakeCase() string

SnakeCase returns the enum as a snake_case string.

func (ErrorCode) String

func (x ErrorCode) String() string

String implements the Stringer interface.

func (ErrorCode) TrainCase

func (x ErrorCode) TrainCase() string

TrainCase returns the enum value as a TRAIN-CASE string.

func (ErrorCode) Type

func (x ErrorCode) Type() string

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

func (x *ErrorCode) UnmarshalCSV(b []byte) error

UnmarshalCSV implements the csvutil.Unmarshaler interface. (https://godoc.org/github.com/jszwec/csvutil#Unmarshaler)

func (*ErrorCode) UnmarshalJSON

func (x *ErrorCode) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*ErrorCode) UnmarshalText

func (x *ErrorCode) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface and allows ErrorCode values to be decoded from anything using this generic interface.

func (*ErrorCode) UnmarshalYAML

func (x *ErrorCode) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (ErrorCode) Value

func (x ErrorCode) Value() (driver.Value, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL