Documentation
¶
Overview ¶
Package types provides custom Go types for OpenAPI format mappings: Date, Email, UUID, File, and the generic Nullable[T] wrapper.
Index ¶
- Constants
- Variables
- type Date
- type Email
- type File
- func (file File) Bytes() ([]byte, error)
- func (file File) FileSize() int64
- func (file File) Filename() string
- func (file *File) InitFromBytes(data []byte, filename string)
- func (file *File) InitFromMultipart(header *multipart.FileHeader)
- func (file File) MarshalJSON() ([]byte, error)
- func (file File) Reader() (io.ReadCloser, error)
- func (file *File) UnmarshalJSON(data []byte) error
- type Nullable
- func (n Nullable[T]) Get() (T, error)
- func (n Nullable[T]) IsNull() bool
- func (n Nullable[T]) IsSpecified() bool
- func (n Nullable[T]) MarshalJSON() ([]byte, error)
- func (n Nullable[T]) MustGet() T
- func (n *Nullable[T]) Set(value T)
- func (n *Nullable[T]) SetNull()
- func (n *Nullable[T]) SetUnspecified()
- func (n *Nullable[T]) UnmarshalJSON(data []byte) error
- type UUID
Constants ¶
const DateFormat = "2006-01-02"
Variables ¶
var ErrNullableIsNull = errors.New("nullable value is null")
ErrNullableIsNull is returned when trying to get a value from a null Nullable.
var ErrNullableNotSpecified = errors.New("nullable value is not specified")
ErrNullableNotSpecified is returned when trying to get a value from an unspecified Nullable.
var ErrValidationEmail = errors.New("email: failed to pass regex validation")
ErrValidationEmail is the sentinel error returned when an email fails validation
Functions ¶
This section is empty.
Types ¶
type Date ¶
func (Date) MarshalJSON ¶
func (Date) MarshalText ¶
MarshalText implements encoding.TextMarshaler for Date.
func (*Date) UnmarshalJSON ¶
func (*Date) UnmarshalText ¶
type Email ¶
type Email string
Email represents an email address. It is a string type that must pass regex validation before being marshalled to JSON or unmarshalled from JSON.
func (Email) MarshalJSON ¶
func (*Email) UnmarshalJSON ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
func (*File) InitFromBytes ¶
func (*File) InitFromMultipart ¶
func (file *File) InitFromMultipart(header *multipart.FileHeader)
func (File) MarshalJSON ¶
func (*File) UnmarshalJSON ¶
type Nullable ¶
Nullable is a generic type that can distinguish between: - Field not provided (unspecified) - Field explicitly set to null - Field has a value
This is implemented as a map[bool]T where: - Empty map: unspecified - map[false]T: explicitly null - map[true]T: has a value
func NewNullNullable ¶
NewNullNullable creates a Nullable that is explicitly null.
func NewNullableWithValue ¶
NewNullableWithValue creates a Nullable with the given value.
func (Nullable[T]) IsSpecified ¶
IsSpecified returns true if the field was provided (either null or a value).
func (Nullable[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Nullable[T]) MustGet ¶
func (n Nullable[T]) MustGet() T
MustGet returns the value or panics if null or unspecified.
func (*Nullable[T]) SetNull ¶
func (n *Nullable[T]) SetNull()
SetNull marks the field as explicitly null.
func (*Nullable[T]) SetUnspecified ¶
func (n *Nullable[T]) SetUnspecified()
SetUnspecified clears the field (as if it was never set).
func (*Nullable[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.