Documentation
¶
Overview ¶
Package enums holds two enum types exactly as `aru make:enum` writes them, so that what depends on the enum contract is tested against the file a project actually gets rather than against a hand-written stand-in.
Nothing here is edited. Each type is copied in as generated, which is what makes a failure here mean the generator and the contract have drifted apart -- the only failure worth having in this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InvoiceStatus ¶
type InvoiceStatus string
InvoiceStatus is the closed set of values the column may hold.
Go has no enum keyword, so this is the shape that gets the guarantee anyway: a named type, constants that are the only valid values, and a Scan/Value pair so a value the application does not know about is an error at the read rather than a zero value that silently behaves like the first case.
That last part is the whole reason the file is this long: nothing refuses an unknown value unless the type does, and a plain `type InvoiceStatus string` accepts anything the database hands it.
const ( InvoiceStatusDraft InvoiceStatus = "draft" InvoiceStatusSent InvoiceStatus = "sent" InvoiceStatusPaid InvoiceStatus = "paid" InvoiceStatusVoid InvoiceStatus = "void" )
The values. Stored exactly as written -- renaming a constant must never rewrite a column.
func InvoiceStatusValues ¶
func InvoiceStatusValues() []InvoiceStatus
InvoiceStatusValues lists them in declaration order.
It feeds a <select> in a kyse view and it is what a test asserts against, so adding a value without deciding what the form and the migration do about it shows up as a failure.
func ParseInvoiceStatus ¶
func ParseInvoiceStatus(s string) (InvoiceStatus, error)
ParseInvoiceStatus turns request input into the type, or says why it cannot.
app/Http/Requests calls it, so a value outside the set becomes a field error the form can show rather than a row.
func (InvoiceStatus) Label ¶
func (v InvoiceStatus) Label() string
Label is what a form shows.
Separate from String on purpose: the stored value is a contract with the database and with every consumer of an event, and the label is a contract with nobody. Changing a label must not be able to change a row.
func (*InvoiceStatus) Scan ¶
func (v *InvoiceStatus) Scan(src any) error
Scan implements sql.Scanner.
A value the application does not know about is an error here, at the row that has it, rather than a silent fallback three layers up. That is usually a migration that added a value the binary being rolled out does not have yet, which is why a migration must stay compatible with the previous binary.
func (InvoiceStatus) String ¶
func (v InvoiceStatus) String() string
String is the stored value, so fmt and a view print it unchanged.
func (InvoiceStatus) Valid ¶
func (v InvoiceStatus) Valid() bool
Valid reports whether v is one of the values.
type Priority ¶
type Priority int
Priority is the closed set of values the column may hold.
Go has no enum keyword, so this is the shape that gets the guarantee anyway: a named type, constants that are the only valid values, and a Scan/Value pair so a value the application does not know about is an error at the read rather than a zero value that silently behaves like the first case.
That last part is the whole reason the file is this long: nothing refuses an unknown value unless the type does, and a plain `type Priority int` accepts anything the database hands it.
The values. The numbers are explicit and never iota: iota renumbers everything below an insertion, and the numbers are already in the database.
func ParsePriority ¶
ParsePriority turns request input into the type, or says why it cannot.
app/Http/Requests calls it, so a value outside the set becomes a field error the form can show rather than a row.
func PriorityValues ¶
func PriorityValues() []Priority
PriorityValues lists them in declaration order.
It feeds a <select> in a kyse view and it is what a test asserts against, so adding a value without deciding what the form and the migration do about it shows up as a failure.
func (Priority) Label ¶
Label is what a form shows.
Separate from String on purpose: the stored value is a contract with the database and with every consumer of an event, and the label is a contract with nobody. Changing a label must not be able to change a row.
func (*Priority) Scan ¶
Scan implements sql.Scanner.
A value the application does not know about is an error here, at the row that has it, rather than a silent fallback three layers up. That is usually a migration that added a value the binary being rolled out does not have yet, which is why a migration must stay compatible with the previous binary.
func (Priority) String ¶
String is the name of the value, because the stored one is a number and a number in a log is a lookup somebody has to do at three in the morning.