types

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 715

Documentation

Index

Constants

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

Variables

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) Bind added in v1.2.0

func (d *Date) Bind(src string) error

Bind implements the runtime.Binder interface so that Date is treated as a scalar value when binding query parameters rather than being decomposed as a struct with key-value pairs.

func (Date) MarshalJSON

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

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 Duration added in v1.5.0

type Duration struct {
	Years  int
	Months int
	Weeks  int
	Days   int

	Hours   int
	Minutes int
	// Seconds may carry a fraction (e.g. "PT0.5S"). Strictly, RFC 3339
	// allows only integer components; ISO 8601 permits a fraction on the
	// smallest component, and real-world payloads use it, so fractional
	// seconds are accepted when parsing and emitted when present.
	Seconds float64
}

Duration represents an RFC 3339 duration (the ISO 8601 duration grammar referenced by the OpenAPI "duration" format), e.g. "P3Y6M4DT12H30M5S". See https://spec.openapis.org/registry/format/duration

Calendar components (years, months, weeks, days) have no fixed length in wall-clock time, so the components are stored as parsed instead of being converted to a time.Duration; any spec-valid duration round-trips losslessly through ParseDuration and String. Use TimeDuration and FromTimeDuration to bridge to time.Duration where the conversion is well-defined.

The RFC 3339 grammar makes weeks exclusive ("P2W" cannot be combined with other components); ParseDuration enforces that, but the struct cannot. A hand-built value mixing Weeks with other components serializes with the week between the months and days, which is outside the strict grammar.

func FromTimeDuration added in v1.5.0

func FromTimeDuration(td time.Duration) (Duration, error)

FromTimeDuration decomposes a time.Duration into hours, minutes and seconds. RFC 3339 durations cannot be negative, so a negative input is an error.

func ParseDuration added in v1.5.0

func ParseDuration(s string) (Duration, error)

ParseDuration parses an RFC 3339 duration string per the grammar in RFC 3339 appendix A: "P" followed by ordered date components ("1Y2M3D"), a time part introduced by "T" ("T4H5M6S"), or a standalone week component ("2W"). At least one component must be present. As an interoperability extension beyond the strict grammar, the seconds component may carry a fraction, with either a period or a comma ("PT0.5S", "PT0,5S").

func (*Duration) Bind added in v1.5.0

func (d *Duration) Bind(src string) error

Bind implements the runtime.Binder interface so that Duration is treated as a scalar value when binding parameters rather than being decomposed as a struct with key-value pairs.

func (Duration) MarshalJSON added in v1.5.0

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

func (Duration) MarshalText added in v1.5.0

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

func (Duration) String added in v1.5.0

func (d Duration) String() string

String serializes the duration in RFC 3339 form, omitting zero components. The all-zero duration serializes as "PT0S".

func (Duration) TimeDuration added in v1.5.0

func (d Duration) TimeDuration() (time.Duration, error)

TimeDuration converts to a time.Duration. Years and months have no fixed length, so their presence is an error; weeks and days are converted with the common fixed convention of 7-day weeks and 24-hour days, which ignores calendar effects such as DST transitions.

func (*Duration) UnmarshalJSON added in v1.5.0

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

func (*Duration) UnmarshalText added in v1.5.0

func (d *Duration) 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 UUID

type UUID = uuid.UUID

Jump to

Keyboard shortcuts

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