types

package
v0.0.0-...-bb4e2af Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package types provides custom Go types for OpenAPI format mappings: Date, Email, UUID, File, and the generic Nullable[T] wrapper.

Index

Constants

View Source
const DateFormat = "2006-01-02"

Variables

View Source
var ErrNullableIsNull = errors.New("nullable value is null")

ErrNullableIsNull is returned when trying to get a value from a null Nullable.

View Source
var ErrNullableNotSpecified = errors.New("nullable value is not specified")

ErrNullableNotSpecified is returned when trying to get a value from an unspecified Nullable.

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

type Date struct {
	time.Time
}

func (Date) Format

func (d Date) Format(layout string) string

Format returns the date formatted according to layout.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for Date.

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(data []byte) error

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 (e Email) MarshalJSON() ([]byte, error)

func (*Email) UnmarshalJSON

func (e *Email) UnmarshalJSON(data []byte) error

type File

type File struct {
	// contains filtered or unexported fields
}

func (File) Bytes

func (file File) Bytes() ([]byte, error)

func (File) FileSize

func (file File) FileSize() int64

func (File) Filename

func (file File) Filename() string

func (*File) InitFromBytes

func (file *File) InitFromBytes(data []byte, filename string)

func (*File) InitFromMultipart

func (file *File) InitFromMultipart(header *multipart.FileHeader)

func (File) MarshalJSON

func (file File) MarshalJSON() ([]byte, error)

func (File) Reader

func (file File) Reader() (io.ReadCloser, error)

func (*File) UnmarshalJSON

func (file *File) UnmarshalJSON(data []byte) error

type Nullable

type Nullable[T any] map[bool]T

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

func NewNullNullable[T any]() Nullable[T]

NewNullNullable creates a Nullable that is explicitly null.

func NewNullableWithValue

func NewNullableWithValue[T any](value T) Nullable[T]

NewNullableWithValue creates a Nullable with the given value.

func (Nullable[T]) Get

func (n Nullable[T]) Get() (T, error)

Get returns the value if set, or an error if null or unspecified.

func (Nullable[T]) IsNull

func (n Nullable[T]) IsNull() bool

IsNull returns true if the field is explicitly null.

func (Nullable[T]) IsSpecified

func (n Nullable[T]) IsSpecified() bool

IsSpecified returns true if the field was provided (either null or a value).

func (Nullable[T]) MarshalJSON

func (n Nullable[T]) MarshalJSON() ([]byte, error)

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]) Set

func (n *Nullable[T]) Set(value T)

Set assigns a value.

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

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type UUID

type UUID = uuid.UUID

Jump to

Keyboard shortcuts

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