Documentation
¶
Overview ¶
Package strfmt contains custom string formats.
Index ¶
- Constants
- Variables
- func DefaultNameNormalizer(name string) string
- func IsBSONObjectID(str string) bool
- func IsCountry(str string) bool
- func IsCurrency(str string) bool
- func IsDate(str string) bool
- func IsDateTime(str string) bool
- func IsDuration(str string) bool
- func IsDurationISO8601(s string) bool
- func IsEmail(str string) bool
- func IsHostname(str string) bool
- func IsULID(str string) bool
- func IsUUID(str string) bool
- func IsUUID3(str string) bool
- func IsUUID4(str string) bool
- func IsUUID5(str string) bool
- func IsUUID7(str string) bool
- func JSONSchema2020Normalizer(name string) string
- func ParseDuration(s string) (time.Duration, error)
- func ParseISO8601Duration(s string, opts ...ISODurationOption) (time.Duration, error)
- type Base64
- func (b *Base64) DeepCopy() *Base64
- func (b *Base64) DeepCopyInto(out *Base64)
- func (b Base64) MarshalBSON() ([]byte, error)
- func (b Base64) MarshalJSON() ([]byte, error)
- func (b Base64) MarshalText() ([]byte, error)
- func (b *Base64) Scan(raw any) error
- func (b Base64) String() string
- func (b *Base64) UnmarshalBSON(data []byte) error
- func (b *Base64) UnmarshalJSON(data []byte) error
- func (b *Base64) UnmarshalText(data []byte) error
- func (b Base64) Value() (driver.Value, error)
- type CIDR
- func (u *CIDR) DeepCopy() *CIDR
- func (u *CIDR) DeepCopyInto(out *CIDR)
- func (u CIDR) MarshalBSON() ([]byte, error)
- func (u CIDR) MarshalJSON() ([]byte, error)
- func (u CIDR) MarshalText() ([]byte, error)
- func (u *CIDR) Scan(raw any) error
- func (u CIDR) String() string
- func (u *CIDR) UnmarshalBSON(data []byte) error
- func (u *CIDR) UnmarshalJSON(data []byte) error
- func (u *CIDR) UnmarshalText(data []byte) error
- func (u CIDR) Value() (driver.Value, error)
- type Country
- func (u *Country) DeepCopy() *Country
- func (u *Country) DeepCopyInto(out *Country)
- func (u *Country) GobDecode(data []byte) error
- func (u Country) GobEncode() ([]byte, error)
- func (u Country) MarshalBSON() ([]byte, error)
- func (u Country) MarshalBinary() ([]byte, error)
- func (u Country) MarshalJSON() ([]byte, error)
- func (u Country) MarshalText() ([]byte, error)
- func (u *Country) Scan(raw any) error
- func (u Country) String() string
- func (u *Country) UnmarshalBSON(data []byte) error
- func (u *Country) UnmarshalBinary(data []byte) error
- func (u *Country) UnmarshalJSON(data []byte) error
- func (u *Country) UnmarshalText(data []byte) error
- func (u Country) Value() (driver.Value, error)
- type CreditCard
- func (u *CreditCard) DeepCopy() *CreditCard
- func (u *CreditCard) DeepCopyInto(out *CreditCard)
- func (u CreditCard) MarshalBSON() ([]byte, error)
- func (u CreditCard) MarshalJSON() ([]byte, error)
- func (u CreditCard) MarshalText() ([]byte, error)
- func (u *CreditCard) Scan(raw any) error
- func (u CreditCard) String() string
- func (u *CreditCard) UnmarshalBSON(data []byte) error
- func (u *CreditCard) UnmarshalJSON(data []byte) error
- func (u *CreditCard) UnmarshalText(data []byte) error
- func (u CreditCard) Value() (driver.Value, error)
- type Currency
- func (u *Currency) DeepCopy() *Currency
- func (u *Currency) DeepCopyInto(out *Currency)
- func (u *Currency) GobDecode(data []byte) error
- func (u Currency) GobEncode() ([]byte, error)
- func (u Currency) MarshalBSON() ([]byte, error)
- func (u Currency) MarshalBinary() ([]byte, error)
- func (u Currency) MarshalJSON() ([]byte, error)
- func (u Currency) MarshalText() ([]byte, error)
- func (u *Currency) Scan(raw any) error
- func (u Currency) String() string
- func (u *Currency) UnmarshalBSON(data []byte) error
- func (u *Currency) UnmarshalBinary(data []byte) error
- func (u *Currency) UnmarshalJSON(data []byte) error
- func (u *Currency) UnmarshalText(data []byte) error
- func (u Currency) Value() (driver.Value, error)
- type Date
- func (d *Date) DeepCopy() *Date
- func (d *Date) DeepCopyInto(out *Date)
- func (d Date) Equal(d2 Date) bool
- func (d *Date) GobDecode(data []byte) error
- func (d Date) GobEncode() ([]byte, error)
- func (d Date) MarshalBSON() ([]byte, error)
- func (d Date) MarshalBinary() ([]byte, error)
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) MarshalText() ([]byte, error)
- func (d *Date) Scan(raw any) error
- func (d Date) String() string
- func (d *Date) UnmarshalBSON(data []byte) error
- func (d *Date) UnmarshalBinary(data []byte) error
- func (d *Date) UnmarshalJSON(data []byte) error
- func (d *Date) UnmarshalText(text []byte) error
- func (d Date) Value() (driver.Value, error)
- type DateTime
- func (t *DateTime) DeepCopy() *DateTime
- func (t *DateTime) DeepCopyInto(out *DateTime)
- func (t DateTime) Equal(t2 DateTime) bool
- func (t *DateTime) GobDecode(data []byte) error
- func (t DateTime) GobEncode() ([]byte, error)
- func (t DateTime) IsUnixZero() bool
- func (t DateTime) IsZero() bool
- func (t DateTime) MarshalBSON() ([]byte, error)
- func (t DateTime) MarshalBSONValue() (byte, []byte, error)
- func (t DateTime) MarshalBinary() ([]byte, error)
- func (t DateTime) MarshalJSON() ([]byte, error)
- func (t DateTime) MarshalText() ([]byte, error)
- func (t *DateTime) Scan(raw any) error
- func (t DateTime) String() string
- func (t *DateTime) UnmarshalBSON(data []byte) error
- func (t *DateTime) UnmarshalBSONValue(tpe byte, data []byte) error
- func (t *DateTime) UnmarshalBinary(data []byte) error
- func (t *DateTime) UnmarshalJSON(data []byte) error
- func (t *DateTime) UnmarshalText(text []byte) error
- func (t DateTime) Value() (driver.Value, error)
- type Duration
- func (d *Duration) DeepCopy() *Duration
- func (d *Duration) DeepCopyInto(out *Duration)
- func (d Duration) MarshalBSON() ([]byte, error)
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) MarshalText() ([]byte, error)
- func (d *Duration) Scan(raw any) error
- func (d Duration) String() string
- func (d *Duration) UnmarshalBSON(data []byte) error
- func (d *Duration) UnmarshalJSON(data []byte) error
- func (d *Duration) UnmarshalText(data []byte) error
- func (d Duration) Value() (driver.Value, error)
- type DurationISO8601
- type DurationLenient
- type DurationStrict
- type Email
- func (e *Email) DeepCopy() *Email
- func (e *Email) DeepCopyInto(out *Email)
- func (e Email) MarshalBSON() ([]byte, error)
- func (e Email) MarshalJSON() ([]byte, error)
- func (e Email) MarshalText() ([]byte, error)
- func (e *Email) Scan(raw any) error
- func (e Email) String() string
- func (e *Email) UnmarshalBSON(data []byte) error
- func (e *Email) UnmarshalJSON(data []byte) error
- func (e *Email) UnmarshalText(data []byte) error
- func (e Email) Value() (driver.Value, error)
- type Format
- type HexColor
- func (h *HexColor) DeepCopy() *HexColor
- func (h *HexColor) DeepCopyInto(out *HexColor)
- func (h HexColor) MarshalBSON() ([]byte, error)
- func (h HexColor) MarshalJSON() ([]byte, error)
- func (h HexColor) MarshalText() ([]byte, error)
- func (h *HexColor) Scan(raw any) error
- func (h HexColor) String() string
- func (h *HexColor) UnmarshalBSON(data []byte) error
- func (h *HexColor) UnmarshalJSON(data []byte) error
- func (h *HexColor) UnmarshalText(data []byte) error
- func (h HexColor) Value() (driver.Value, error)
- type Hostname
- func (h *Hostname) DeepCopy() *Hostname
- func (h *Hostname) DeepCopyInto(out *Hostname)
- func (h Hostname) MarshalBSON() ([]byte, error)
- func (h Hostname) MarshalJSON() ([]byte, error)
- func (h Hostname) MarshalText() ([]byte, error)
- func (h *Hostname) Scan(raw any) error
- func (h Hostname) String() string
- func (h *Hostname) UnmarshalBSON(data []byte) error
- func (h *Hostname) UnmarshalJSON(data []byte) error
- func (h *Hostname) UnmarshalText(data []byte) error
- func (h Hostname) Value() (driver.Value, error)
- type IPv4
- func (u *IPv4) DeepCopy() *IPv4
- func (u *IPv4) DeepCopyInto(out *IPv4)
- func (u IPv4) MarshalBSON() ([]byte, error)
- func (u IPv4) MarshalJSON() ([]byte, error)
- func (u IPv4) MarshalText() ([]byte, error)
- func (u *IPv4) Scan(raw any) error
- func (u IPv4) String() string
- func (u *IPv4) UnmarshalBSON(data []byte) error
- func (u *IPv4) UnmarshalJSON(data []byte) error
- func (u *IPv4) UnmarshalText(data []byte) error
- func (u IPv4) Value() (driver.Value, error)
- type IPv6
- func (u *IPv6) DeepCopy() *IPv6
- func (u *IPv6) DeepCopyInto(out *IPv6)
- func (u IPv6) MarshalBSON() ([]byte, error)
- func (u IPv6) MarshalJSON() ([]byte, error)
- func (u IPv6) MarshalText() ([]byte, error)
- func (u *IPv6) Scan(raw any) error
- func (u IPv6) String() string
- func (u *IPv6) UnmarshalBSON(data []byte) error
- func (u *IPv6) UnmarshalJSON(data []byte) error
- func (u *IPv6) UnmarshalText(data []byte) error
- func (u IPv6) Value() (driver.Value, error)
- type ISBN
- func (u *ISBN) DeepCopy() *ISBN
- func (u *ISBN) DeepCopyInto(out *ISBN)
- func (u ISBN) MarshalBSON() ([]byte, error)
- func (u ISBN) MarshalJSON() ([]byte, error)
- func (u ISBN) MarshalText() ([]byte, error)
- func (u *ISBN) Scan(raw any) error
- func (u ISBN) String() string
- func (u *ISBN) UnmarshalBSON(data []byte) error
- func (u *ISBN) UnmarshalJSON(data []byte) error
- func (u *ISBN) UnmarshalText(data []byte) error
- func (u ISBN) Value() (driver.Value, error)
- type ISBN10
- func (u *ISBN10) DeepCopy() *ISBN10
- func (u *ISBN10) DeepCopyInto(out *ISBN10)
- func (u ISBN10) MarshalBSON() ([]byte, error)
- func (u ISBN10) MarshalJSON() ([]byte, error)
- func (u ISBN10) MarshalText() ([]byte, error)
- func (u *ISBN10) Scan(raw any) error
- func (u ISBN10) String() string
- func (u *ISBN10) UnmarshalBSON(data []byte) error
- func (u *ISBN10) UnmarshalJSON(data []byte) error
- func (u *ISBN10) UnmarshalText(data []byte) error
- func (u ISBN10) Value() (driver.Value, error)
- type ISBN13
- func (u *ISBN13) DeepCopy() *ISBN13
- func (u *ISBN13) DeepCopyInto(out *ISBN13)
- func (u ISBN13) MarshalBSON() ([]byte, error)
- func (u ISBN13) MarshalJSON() ([]byte, error)
- func (u ISBN13) MarshalText() ([]byte, error)
- func (u *ISBN13) Scan(raw any) error
- func (u ISBN13) String() string
- func (u *ISBN13) UnmarshalBSON(data []byte) error
- func (u *ISBN13) UnmarshalJSON(data []byte) error
- func (u *ISBN13) UnmarshalText(data []byte) error
- func (u ISBN13) Value() (driver.Value, error)
- type ISODuration
- func (d *ISODuration[P]) DeepCopy() *ISODuration[P]
- func (d *ISODuration[P]) DeepCopyInto(out *ISODuration[P])
- func (d ISODuration[P]) Equal(other ISODuration[P]) bool
- func (d ISODuration[P]) MarshalBSON() ([]byte, error)
- func (d ISODuration[P]) MarshalJSON() ([]byte, error)
- func (d ISODuration[P]) MarshalText() ([]byte, error)
- func (d *ISODuration[P]) Scan(raw any) error
- func (d ISODuration[P]) String() string
- func (d *ISODuration[P]) UnmarshalBSON(data []byte) error
- func (d *ISODuration[P]) UnmarshalJSON(data []byte) error
- func (d *ISODuration[P]) UnmarshalText(text []byte) error
- func (d ISODuration[P]) Value() (driver.Value, error)
- type ISODurationOption
- type ISODurationPolicy
- type MAC
- func (u *MAC) DeepCopy() *MAC
- func (u *MAC) DeepCopyInto(out *MAC)
- func (u MAC) MarshalBSON() ([]byte, error)
- func (u MAC) MarshalJSON() ([]byte, error)
- func (u MAC) MarshalText() ([]byte, error)
- func (u *MAC) Scan(raw any) error
- func (u MAC) String() string
- func (u *MAC) UnmarshalBSON(data []byte) error
- func (u *MAC) UnmarshalJSON(data []byte) error
- func (u *MAC) UnmarshalText(data []byte) error
- func (u MAC) Value() (driver.Value, error)
- type NameNormalizer
- type ObjectId
- func (id *ObjectId) DeepCopy() *ObjectId
- func (id *ObjectId) DeepCopyInto(out *ObjectId)
- func (id ObjectId) Hex() string
- func (id ObjectId) MarshalBSON() ([]byte, error)
- func (id ObjectId) MarshalBSONValue() (byte, []byte, error)
- func (id ObjectId) MarshalJSON() ([]byte, error)
- func (id ObjectId) MarshalText() ([]byte, error)
- func (id *ObjectId) Scan(raw any) error
- func (id ObjectId) String() string
- func (id *ObjectId) UnmarshalBSON(data []byte) error
- func (id *ObjectId) UnmarshalBSONValue(_ byte, data []byte) error
- func (id *ObjectId) UnmarshalJSON(data []byte) error
- func (id *ObjectId) UnmarshalText(data []byte) error
- func (id ObjectId) Value() (driver.Value, error)
- type Password
- func (r *Password) DeepCopy() *Password
- func (r *Password) DeepCopyInto(out *Password)
- func (r Password) MarshalBSON() ([]byte, error)
- func (r Password) MarshalJSON() ([]byte, error)
- func (r Password) MarshalText() ([]byte, error)
- func (r *Password) Scan(raw any) error
- func (r Password) String() string
- func (r *Password) UnmarshalBSON(data []byte) error
- func (r *Password) UnmarshalJSON(data []byte) error
- func (r *Password) UnmarshalText(data []byte) error
- func (r Password) Value() (driver.Value, error)
- type RGBColor
- func (r *RGBColor) DeepCopy() *RGBColor
- func (r *RGBColor) DeepCopyInto(out *RGBColor)
- func (r RGBColor) MarshalBSON() ([]byte, error)
- func (r RGBColor) MarshalJSON() ([]byte, error)
- func (r RGBColor) MarshalText() ([]byte, error)
- func (r *RGBColor) Scan(raw any) error
- func (r RGBColor) String() string
- func (r *RGBColor) UnmarshalBSON(data []byte) error
- func (r *RGBColor) UnmarshalJSON(data []byte) error
- func (r *RGBColor) UnmarshalText(data []byte) error
- func (r RGBColor) Value() (driver.Value, error)
- type Registry
- type SSN
- func (u *SSN) DeepCopy() *SSN
- func (u *SSN) DeepCopyInto(out *SSN)
- func (u SSN) MarshalBSON() ([]byte, error)
- func (u SSN) MarshalJSON() ([]byte, error)
- func (u SSN) MarshalText() ([]byte, error)
- func (u *SSN) Scan(raw any) error
- func (u SSN) String() string
- func (u *SSN) UnmarshalBSON(data []byte) error
- func (u *SSN) UnmarshalJSON(data []byte) error
- func (u *SSN) UnmarshalText(data []byte) error
- func (u SSN) Value() (driver.Value, error)
- type ULID
- func (u *ULID) DeepCopy() *ULID
- func (u *ULID) DeepCopyInto(out *ULID)
- func (u ULID) Equal(other ULID) bool
- func (u *ULID) GetULID() any
- func (u *ULID) GobDecode(data []byte) error
- func (u ULID) GobEncode() ([]byte, error)
- func (u ULID) MarshalBSON() ([]byte, error)
- func (u ULID) MarshalBinary() ([]byte, error)
- func (u ULID) MarshalJSON() ([]byte, error)
- func (u ULID) MarshalText() ([]byte, error)
- func (u *ULID) Scan(raw any) error
- func (u ULID) String() string
- func (u *ULID) UnmarshalBSON(data []byte) error
- func (u *ULID) UnmarshalBinary(data []byte) error
- func (u *ULID) UnmarshalJSON(data []byte) error
- func (u *ULID) UnmarshalText(data []byte) error
- func (u ULID) Value() (driver.Value, error)
- type URI
- func (u *URI) DeepCopy() *URI
- func (u *URI) DeepCopyInto(out *URI)
- func (u URI) MarshalBSON() ([]byte, error)
- func (u URI) MarshalJSON() ([]byte, error)
- func (u URI) MarshalText() ([]byte, error)
- func (u *URI) Scan(raw any) error
- func (u URI) String() string
- func (u *URI) UnmarshalBSON(data []byte) error
- func (u *URI) UnmarshalJSON(data []byte) error
- func (u *URI) UnmarshalText(data []byte) error
- func (u URI) Value() (driver.Value, error)
- type UUID
- func (u *UUID) DeepCopy() *UUID
- func (u *UUID) DeepCopyInto(out *UUID)
- func (u UUID) MarshalBSON() ([]byte, error)
- func (u UUID) MarshalJSON() ([]byte, error)
- func (u UUID) MarshalText() ([]byte, error)
- func (u *UUID) Scan(raw any) error
- func (u UUID) String() string
- func (u *UUID) UnmarshalBSON(data []byte) error
- func (u *UUID) UnmarshalJSON(data []byte) error
- func (u *UUID) UnmarshalText(data []byte) error
- func (u UUID) Value() (driver.Value, error)
- type UUID3
- func (u *UUID3) DeepCopy() *UUID3
- func (u *UUID3) DeepCopyInto(out *UUID3)
- func (u UUID3) MarshalBSON() ([]byte, error)
- func (u UUID3) MarshalJSON() ([]byte, error)
- func (u UUID3) MarshalText() ([]byte, error)
- func (u *UUID3) Scan(raw any) error
- func (u UUID3) String() string
- func (u *UUID3) UnmarshalBSON(data []byte) error
- func (u *UUID3) UnmarshalJSON(data []byte) error
- func (u *UUID3) UnmarshalText(data []byte) error
- func (u UUID3) Value() (driver.Value, error)
- type UUID4
- func (u *UUID4) DeepCopy() *UUID4
- func (u *UUID4) DeepCopyInto(out *UUID4)
- func (u UUID4) MarshalBSON() ([]byte, error)
- func (u UUID4) MarshalJSON() ([]byte, error)
- func (u UUID4) MarshalText() ([]byte, error)
- func (u *UUID4) Scan(raw any) error
- func (u UUID4) String() string
- func (u *UUID4) UnmarshalBSON(data []byte) error
- func (u *UUID4) UnmarshalJSON(data []byte) error
- func (u *UUID4) UnmarshalText(data []byte) error
- func (u UUID4) Value() (driver.Value, error)
- type UUID5
- func (u *UUID5) DeepCopy() *UUID5
- func (u *UUID5) DeepCopyInto(out *UUID5)
- func (u UUID5) MarshalBSON() ([]byte, error)
- func (u UUID5) MarshalJSON() ([]byte, error)
- func (u UUID5) MarshalText() ([]byte, error)
- func (u *UUID5) Scan(raw any) error
- func (u UUID5) String() string
- func (u *UUID5) UnmarshalBSON(data []byte) error
- func (u *UUID5) UnmarshalJSON(data []byte) error
- func (u *UUID5) UnmarshalText(data []byte) error
- func (u UUID5) Value() (driver.Value, error)
- type UUID7
- func (u *UUID7) DeepCopy() *UUID7
- func (u *UUID7) DeepCopyInto(out *UUID7)
- func (u UUID7) MarshalBSON() ([]byte, error)
- func (u UUID7) MarshalJSON() ([]byte, error)
- func (u UUID7) MarshalText() ([]byte, error)
- func (u *UUID7) Scan(raw any) error
- func (u UUID7) String() string
- func (u *UUID7) UnmarshalBSON(data []byte) error
- func (u *UUID7) UnmarshalJSON(data []byte) error
- func (u *UUID7) UnmarshalText(data []byte) error
- func (u UUID7) Value() (driver.Value, error)
- type Validator
Examples ¶
Constants ¶
const ( // UUIDPattern Regex for [UUID] that allows uppercase. // // Deprecated: [strfmt] no longer uses regular expressions to validate UUIDs. UUIDPattern = `(?i)(^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$)|(^[0-9a-f]{32}$)` // UUID3Pattern Regex for [UUID3] that allows uppercase. // // Deprecated: [strfmt] no longer uses regular expressions to validate UUIDs. UUID3Pattern = `(?i)(^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$)|(^[0-9a-f]{12}3[0-9a-f]{3}?[0-9a-f]{16}$)` // UUID4Pattern Regex for [UUID4] that allows uppercase. // // Deprecated: [strfmt] no longer uses regular expressions to validate UUIDs. UUID4Pattern = `(?i)(^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$)|(^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$)` // UUID5Pattern Regex for [UUID]5 that allows uppercase. // // Deprecated: [strfmt] no longer uses regular expressions to validate UUIDs. UUID5Pattern = `(?i)(^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$)|(^[0-9a-f]{12}5[0-9a-f]{3}[89ab][0-9a-f]{15}$)` )
const ( // RFC3339Millis represents a ISO8601 format to millis instead of to nanos. RFC3339Millis = "2006-01-02T15:04:05.000Z07:00" // RFC3339MillisNoColon represents a ISO8601 format to millis instead of to nanos. RFC3339MillisNoColon = "2006-01-02T15:04:05.000Z0700" // RFC3339Micro represents a ISO8601 format to micro instead of to nano. RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00" // RFC3339MicroNoColon represents a ISO8601 format to micro instead of to nano. RFC3339MicroNoColon = "2006-01-02T15:04:05.000000Z0700" // ISO8601LocalTime represents a ISO8601 format to ISO8601 in local time (no timezone). ISO8601LocalTime = "2006-01-02T15:04:05" // ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision (dropped secs). ISO8601TimeWithReducedPrecision = "2006-01-02T15:04Z" // ISO8601TimeWithReducedPrecisionLocaltime represents a ISO8601 format with reduced precision and no timezone (dropped seconds + no timezone). ISO8601TimeWithReducedPrecisionLocaltime = "2006-01-02T15:04" // ISO8601TimeUniversalSortableDateTimePattern represents a ISO8601 universal sortable date time pattern. ISO8601TimeUniversalSortableDateTimePattern = "2006-01-02 15:04:05" // ISO8601TimeUniversalSortableDateTimePatternShortForm is the short form of [ISO8601TimeUniversalSortableDateTimePattern]. ISO8601TimeUniversalSortableDateTimePatternShortForm = "2006-01-02" // DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6 DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$` )
const ErrFormat strfmtError = "format error"
ErrFormat is an error raised by the strfmt package.
const ( // HostnamePattern http://[json]-schema.org/latest/[json]-schema-validation.html#anchor114. // // Deprecated: this package no longer uses regular expressions to validate hostnames. HostnamePattern = `^([a-zA-Z0-9\p{S}\p{L}]((-?[a-zA-Z0-9\p{S}\p{L}]{0,62})?)` + `|([a-zA-Z0-9\p{S}\p{L}](([a-zA-Z0-9-\p{S}\p{L}]{0,61}[a-zA-Z0-9\p{S}\p{L}])?)(\.)){1,}([a-zA-Z0-9-\p{L}]){2,63})$` )
const ( // RFC3339FullDate represents a full-date as specified by RFC3339. // See: http://goo.gl/xXOvVd RFC3339FullDate = "2006-01-02" )
Variables ¶
var ( // DateTimeFormats is the collection of formats used by [ParseDateTime](). DateTimeFormats = []string{ RFC3339Micro, RFC3339MicroNoColon, RFC3339Millis, RFC3339MillisNoColon, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime, ISO8601TimeUniversalSortableDateTimePattern, ISO8601TimeUniversalSortableDateTimePatternShortForm, } // MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds). MarshalFormat = RFC3339Millis // NormalizeTimeForMarshal provides a normalization function on time before marshaling (e.g. [time.UTC]). // By default, the time value is not changed. NormalizeTimeForMarshal = func(t time.Time) time.Time { return t } // DefaultTimeLocation provides a location for a time when the time zone is not encoded in the string (ex: ISO8601 Local variants). DefaultTimeLocation = time.UTC )
var ( // ULIDScanDefaultFunc is the default implementation for scanning a [ULID] from a database driver value. ULIDScanDefaultFunc = func(raw any) (ULID, error) { u := NewULIDZero() switch x := raw.(type) { case nil: return u, nil case string: if x == "" { return u, nil } return u, u.UnmarshalText([]byte(x)) case []byte: return u, u.UnmarshalText(x) } return u, fmt.Errorf("cannot sql.Scan() strfmt.ULID from: %#v: %w", raw, ulid.ErrScanValue) } // ULIDScanOverrideFunc allows you to override the Scan method of the [ULID] type. ULIDScanOverrideFunc = ULIDScanDefaultFunc // ULIDValueDefaultFunc is the default implementation for converting a [ULID] to a database driver value. ULIDValueDefaultFunc = func(u ULID) (driver.Value, error) { return driver.Value(u.String()), nil } // ULIDValueOverrideFunc allows you to override the Value method of the [ULID] type. ULIDValueOverrideFunc = ULIDValueDefaultFunc )
var UnixZero = time.Unix(0, 0).UTC() //nolint:gochecknoglobals // package-level sentinel value for unix epoch
UnixZero sets the zero unix UTC timestamp we want to compare against.
Unix 0 for an EST timezone is not equivalent to a UTC timezone.
Functions ¶
func DefaultNameNormalizer ¶
DefaultNameNormalizer removes all dashes.
func IsBSONObjectID ¶
IsBSONObjectID returns true when the string is a valid BSON ObjectId.
func IsCurrency ¶ added in v0.27.0
IsCurrency checks if a string is a valid currency format.
func IsDateTime ¶
IsDateTime returns true when the string is a valid date-time.
JSON datetime format consist of a date and a time separated by a "T", e.g. 2012-04-23T18:25:43.511Z.
func IsDuration ¶
IsDuration returns true if the provided string is a valid duration.
func IsDurationISO8601 ¶ added in v0.27.0
IsDurationISO8601 returns true if the string is a valid strict ISO 8601 duration.
func IsHostname ¶
IsHostname returns true when the string is a valid hostname.
It follows the rules detailed at https://url.spec.whatwg.org/#concept-host-parser and implemented by most modern web browsers.
It supports IDNA rules regarding internationalized names with unicode.
Besides:
- the empty string is not a valid host name
- a trailing dot is allowed in names and IPv4's (not IPv6)
- a host name can be a valid IPv4 (with decimal, octal or hexadecimal numbers) or IPv6 address
- IPv6 zones are disallowed
- top-level domains can be unicode (cf. https://www.iana.org/domains/root/db).
NOTE: this validator doesn't check top-level domains against the IANA root database. It merely ensures that a top-level domain in a FQDN is at least 2 code points long.
func IsULID ¶ added in v0.20.1
IsULID checks if provided string is ULID format Be noticed that this function considers overflowed ULID as non-ulid. For more details see https://github.com/ulid/spec
func IsUUID ¶
IsUUID returns true if the string matches a UUID (in any version, including v6 and v7), upper case is allowed.
func IsUUID7 ¶ added in v0.25.0
IsUUID7 returns true if the string matches a UUID v7, upper case is allowed.
func JSONSchema2020Normalizer ¶ added in v0.27.0
JSONSchema2020Normalizer is like NameNormalizer but adopts "duration-iso8601" as the default "duration" format.
func ParseDuration ¶
ParseDuration parses a duration from a string
It is similar to time.ParseDuration but support additional units like days and weeks, additional abreviations for units and is more tolerant on the presence of blank spaces.
A duration may be negative or fractional.
Differences with [time.ParseDuration] ¶
- more supported units and aliases (see below)
- sign followed by blank space is tolerated
- tolerates blanks between duration and unit (e.g. "300 ms")
Supported units ¶
Units may be specified using aliases or a plural form.
- "ns", "nano", "nanosecond", "nanoseconds", "nanos"
- "us", "µs" (U+00B5 = micro symbol), "μs" (U+03BC = Greek letter mu), "micro", "micros", "microsecond", "microseconds"
- "ms", "milli", "millis", "millisecond", "milliseconds"
- "s", "sec", "secs", "second", "seconds"
- "m", "min", "mins", "minute", "minutes"
- "h", "hr", "hrs", "hour", "hours"
- "d", "day", "days"
- "w", "wk", "wks", "week", "weeks"
NOTE: inspired by scala duration syntax.
Examples ¶
"300ms", "-1.5h", "2h45m", ".5 week", "2 minutes 45 seconds".
func ParseISO8601Duration ¶ added in v0.27.0
func ParseISO8601Duration(s string, opts ...ISODurationOption) (time.Duration, error)
ParseISO8601Duration parses an ISO 8601 / RFC 3339 duration string.
With no options it enforces the strict RFC 3339 Appendix A grammar. Options relax individual rules for programmatic callers.
Example ¶
The strict parser accepts the RFC 3339 Appendix A grammar (the JSON Schema "duration" format) and returns an ordinary time.Duration. Calendar units are collapsed to fixed lengths (year = 365 days, month = 30 days).
package main
import (
"errors"
"fmt"
"github.com/go-openapi/strfmt"
)
func main() {
d, err := strfmt.ParseISO8601Duration("P1DT12H")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(d)
// The strict grammar rejects fractions, signs and whitespace; every rejection
// wraps strfmt.ErrFormat.
_, err = strfmt.ParseISO8601Duration("PT0.5S")
fmt.Println(errors.Is(err, strfmt.ErrFormat))
}
Output: 36h0m0s true
Example (Options) ¶
Options relax individual rules on the explicit ParseISO8601Duration path only — never the registry or struct-field decode path, which stays strict and unambiguous.
package main
import (
"fmt"
"github.com/go-openapi/strfmt"
)
func main() {
// A decimal fraction on the least significant component is opt-in.
frac, _ := strfmt.ParseISO8601Duration("PT0.5S", strfmt.WithISOFractions())
fmt.Println(frac)
// A leading sign is opt-in.
neg, _ := strfmt.ParseISO8601Duration("-PT1H", strfmt.WithISOSign())
fmt.Println(neg)
// WithISOLenient turns on every relaxation at once (fraction, sign, whitespace,
// non-contiguous components, combinable "W"). Ordering is still enforced.
lenient, _ := strfmt.ParseISO8601Duration(" P1Y2D ", strfmt.WithISOLenient())
fmt.Println(lenient)
}
Output: 500ms -1h0m0s 8808h0m0s
Types ¶
type Base64 ¶
type Base64 []byte
Base64 represents a base64 encoded string, using the standard RFC 4648 alphabet.
swagger:strfmt byte.
func (*Base64) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Base64) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (Base64) MarshalJSON ¶
MarshalJSON returns the Base64 as JSON.
func (Base64) MarshalText ¶
MarshalText turns this instance into text.
func (*Base64) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*Base64) UnmarshalJSON ¶
UnmarshalJSON sets the Base64 from JSON.
func (*Base64) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type CIDR ¶ added in v0.19.0
type CIDR string
CIDR represents a Classless Inter-Domain Routing notation.
swagger:strfmt cidr.
func (*CIDR) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (CIDR) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (CIDR) MarshalJSON ¶ added in v0.19.0
MarshalJSON returns the CIDR as JSON.
func (CIDR) MarshalText ¶ added in v0.19.0
MarshalText turns this instance into text.
func (*CIDR) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*CIDR) UnmarshalJSON ¶ added in v0.19.0
UnmarshalJSON sets the CIDR from JSON.
func (*CIDR) UnmarshalText ¶ added in v0.19.0
UnmarshalText hydrates this instance from text.
type Country ¶ added in v0.27.0
Country represents an ISO 3166 country alpha-3 or alpha-2 code as a string format.
swagger:strfmt country.
func ParseCountry ¶ added in v0.27.0
ParseCountry parses a string that represents a valid Country.
func (*Country) DeepCopyInto ¶ added in v0.27.0
DeepCopyInto copies the receiver and writes its value into out.
func (Country) MarshalBSON ¶ added in v0.27.0
MarshalBSON document from this value.
func (Country) MarshalBinary ¶ added in v0.27.0
MarshalBinary implements the encoding.encoding.BinaryMarshaler interface.
func (Country) MarshalJSON ¶ added in v0.27.0
MarshalJSON returns the Country as JSON.
func (Country) MarshalText ¶ added in v0.27.0
MarshalText returns this instance into text.
func (*Country) UnmarshalBSON ¶ added in v0.27.0
UnmarshalBSON document into this value.
func (*Country) UnmarshalBinary ¶ added in v0.27.0
UnmarshalBinary implements the encoding.encoding.BinaryUnmarshaler interface.
func (*Country) UnmarshalJSON ¶ added in v0.27.0
UnmarshalJSON sets the Country from JSON.
func (*Country) UnmarshalText ¶ added in v0.27.0
UnmarshalText hydrates this instance from text.
type CreditCard ¶
type CreditCard string
CreditCard represents a credit card string format.
swagger:strfmt creditcard.
func (*CreditCard) DeepCopy ¶ added in v0.19.0
func (u *CreditCard) DeepCopy() *CreditCard
DeepCopy copies the receiver into a new CreditCard.
func (*CreditCard) DeepCopyInto ¶ added in v0.19.0
func (u *CreditCard) DeepCopyInto(out *CreditCard)
DeepCopyInto copies the receiver and writes its value into out.
func (CreditCard) MarshalBSON ¶ added in v0.19.2
func (u CreditCard) MarshalBSON() ([]byte, error)
MarshalBSON document from this value.
func (CreditCard) MarshalJSON ¶
func (u CreditCard) MarshalJSON() ([]byte, error)
MarshalJSON returns the CreditCard as JSON.
func (CreditCard) MarshalText ¶
func (u CreditCard) MarshalText() ([]byte, error)
MarshalText turns this instance into text.
func (*CreditCard) Scan ¶
func (u *CreditCard) Scan(raw any) error
Scan read a value from a database driver.
func (CreditCard) String ¶
func (u CreditCard) String() string
func (*CreditCard) UnmarshalBSON ¶ added in v0.19.2
func (u *CreditCard) UnmarshalBSON(data []byte) error
UnmarshalBSON document into this value.
func (*CreditCard) UnmarshalJSON ¶
func (u *CreditCard) UnmarshalJSON(data []byte) error
UnmarshalJSON sets the CreditCard from JSON.
func (*CreditCard) UnmarshalText ¶
func (u *CreditCard) UnmarshalText(data []byte) error
UnmarshalText hydrates this instance from text.
type Currency ¶ added in v0.27.0
Currency represents an ISO 4217 currency alpha-3 code as a string format.
Implementation ¶
golang.org/x/text/currency
swagger:strfmt currency.
func ParseCurrency ¶ added in v0.27.0
ParseCurrency parses a string that represents a valid Currency.
func (*Currency) DeepCopyInto ¶ added in v0.27.0
DeepCopyInto copies the receiver and writes its value into out.
func (Currency) MarshalBSON ¶ added in v0.27.0
MarshalBSON document from this value.
func (Currency) MarshalBinary ¶ added in v0.27.0
MarshalBinary implements the encoding.encoding.BinaryMarshaler interface.
func (Currency) MarshalJSON ¶ added in v0.27.0
MarshalJSON returns the Currency as JSON.
func (Currency) MarshalText ¶ added in v0.27.0
MarshalText returns this instance into text.
func (*Currency) UnmarshalBSON ¶ added in v0.27.0
UnmarshalBSON document into this value.
func (*Currency) UnmarshalBinary ¶ added in v0.27.0
UnmarshalBinary implements the encoding.encoding.BinaryUnmarshaler interface.
func (*Currency) UnmarshalJSON ¶ added in v0.27.0
UnmarshalJSON sets the Currency from JSON.
func (*Currency) UnmarshalText ¶ added in v0.27.0
UnmarshalText hydrates this instance from text.
type Date ¶
Date represents a date from the API.
swagger:strfmt date.
func (*Date) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Date) MarshalBSON ¶ added in v0.19.2
func (Date) MarshalBinary ¶ added in v0.19.4
MarshalBinary implements the encoding.encoding.BinaryMarshaler interface.
func (Date) MarshalJSON ¶
MarshalJSON returns the Date as JSON.
func (Date) MarshalText ¶
MarshalText serializes this date type to string.
func (*Date) UnmarshalBSON ¶ added in v0.19.2
func (*Date) UnmarshalBinary ¶ added in v0.19.4
UnmarshalBinary implements the encoding.encoding.BinaryUnmarshaler interface.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON sets the Date from JSON.
func (*Date) UnmarshalText ¶
UnmarshalText parses a text representation into a date type.
type DateTime ¶
DateTime is a time but it serializes to ISO8601 format with millis.
It knows how to read 3 different variations of a RFC3339 date time. Most APIs we encounter want either millisecond or second precision times. This just tries to make it worry-free.
swagger:strfmt date-time.
func MakeDateTime ¶ added in v0.24.0
func MakeDateTime() DateTime
MakeDateTime is a representation of the zero value of the DateTime type (January 1, year 1, 00:00:00 UTC).
You may use DateTime.IsZero to check against this value.
func NewDateTime ¶
func NewDateTime() DateTime
NewDateTime is a representation of the UNIX epoch (January 1, 1970 00:00:00 UTC) for the DateTime type.
Notice that this is not the zero value of the DateTime type.
You may use DateTime.IsUnixZero to check against this value.
func ParseDateTime ¶
ParseDateTime parses a string that represents an ISO8601 time or a unix epoch.
func (*DateTime) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (DateTime) Equal ¶ added in v0.19.12
Equal checks if two DateTime instances are equal using time.Time's Equal method.
func (DateTime) IsUnixZero ¶ added in v0.21.4
IsUnixZero returns whether the date time is equivalent to time.Unix(0, 0).UTC().
func (DateTime) MarshalBSON ¶ added in v0.19.2
MarshalBSON renders the DateTime as a BSON document.
func (DateTime) MarshalBSONValue ¶ added in v0.19.4
MarshalBSONValue marshals a DateTime as a BSON DateTime value (type 0x09), an int64 representing milliseconds since epoch.
MarshalBSONValue is an interface implemented by types that can marshal themselves into a BSON document represented as bytes.
The bytes returned must be a valid BSON document if the error is nil.
func (DateTime) MarshalBinary ¶ added in v0.19.4
MarshalBinary implements the encoding.encoding.BinaryMarshaler interface.
func (DateTime) MarshalJSON ¶
MarshalJSON returns the DateTime as JSON.
func (DateTime) MarshalText ¶
MarshalText implements the text marshaler interface.
func (*DateTime) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON reads the DateTime from a BSON document.
func (*DateTime) UnmarshalBSONValue ¶ added in v0.19.4
UnmarshalBSONValue unmarshals a BSON DateTime value into this DateTime.
func (*DateTime) UnmarshalBinary ¶ added in v0.19.4
UnmarshalBinary implements the encoding.encoding.BinaryUnmarshaler interface.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON sets the DateTime from JSON.
func (*DateTime) UnmarshalText ¶
UnmarshalText implements the text unmarshaler interface.
type Duration ¶
Duration represents a duration
Duration stores a period of time as a nanosecond count, with the largest representable duration being approximately 290 years.
swagger:strfmt duration.
func (*Duration) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Duration) MarshalBSON ¶ added in v0.19.2
func (Duration) MarshalJSON ¶
MarshalJSON returns the Duration as JSON.
func (Duration) MarshalText ¶
MarshalText turns this instance into text.
func (*Duration) UnmarshalBSON ¶ added in v0.19.2
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON sets the Duration from JSON.
func (*Duration) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type DurationISO8601 ¶ added in v0.27.0
type DurationISO8601 = ISODuration[DurationStrict]
DurationISO8601 is the strict, spec-compliant ISO 8601 duration: the JSON Schema draft 2020 "duration" format (RFC 3339 Appendix A).
It binds to the explicit, unambiguous "duration-iso8601" handle. Plain "duration" is a context-dependent default resolved by the registry (Default → human, JSONSchema2020Registry → ISO), not by this static type.
swagger:strfmt duration-iso8601.
Example (Json) ¶
DurationISO8601 is the strict alias; it round-trips through JSON as a canonical ISO 8601 string.
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/go-openapi/strfmt"
)
func main() {
type Payload struct {
Timeout strfmt.DurationISO8601 `json:"timeout"`
}
var p Payload
if err := json.Unmarshal([]byte(`{"timeout":"PT1H30M"}`), &p); err != nil {
fmt.Println(err)
return
}
fmt.Println(time.Duration(p.Timeout))
out, err := json.Marshal(p)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(out))
}
Output: 1h30m0s {"timeout":"PT1H30M"}
Example (Registry) ¶
The format is registered in the Default registry under the "duration-iso8601" handle, distinct from the human-readable "duration" format.
package main
import (
"fmt"
"github.com/go-openapi/strfmt"
)
func main() {
// A plain week duration is valid; strict "W" is exclusive, so combining it is rejected.
fmt.Println(strfmt.Default.Validates("duration-iso8601", "P2W"))
fmt.Println(strfmt.Default.Validates("duration-iso8601", "P2W3D")) // invalid
fmt.Println()
fmt.Println(strfmt.Default.Validates("duration", "2 weeks")) // human duration is the default for duration
fmt.Println(strfmt.Default.Validates("duration", "P2W")) // iso8601 is NOT the default for duration
fmt.Println()
fmt.Println(strfmt.JSONSchema2020Registry.Validates("duration", "P2W")) // iso8601 is the duration for [JSONSchema2020Registry]
fmt.Println(strfmt.JSONSchema2020Registry.Validates("duration", "2 weeks")) // human duration is NOT the default duration for JSONSchema 2020
fmt.Println(strfmt.JSONSchema2020Registry.Validates("duration-human", "2 weeks")) // human duration remain supported as an explicit format
}
Output: true false true false true false true
type DurationLenient ¶ added in v0.27.0
type DurationLenient struct{}
DurationLenient relaxes every strictness knob.
It accepts a decimal fraction on the least significant component, a leading sign, surrounding whitespace, component chains with gaps (e.g. P1Y2D), and a 'W' designator combined with other components.
It remains ordered (P2D1Y is still rejected).
type DurationStrict ¶ added in v0.27.0
type DurationStrict struct{}
DurationStrict is the strict RFC 3339 Appendix A policy.
This is the grammar that the JSON Schema "duration" format is defined against (draft 2020): no fraction, no sign, no whitespace, strict ordering and anchoring, and an exclusive 'W' designator.
type Email ¶
type Email string
Email represents the email string format as specified by the json schema spec.
swagger:strfmt email.
func (*Email) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Email) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (Email) MarshalJSON ¶
MarshalJSON returns the Email as JSON.
func (Email) MarshalText ¶
MarshalText turns this instance into text.
func (*Email) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*Email) UnmarshalJSON ¶
UnmarshalJSON sets the Email from JSON.
func (*Email) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type Format ¶
type Format interface {
String() string
encoding.TextMarshaler
encoding.TextUnmarshaler
}
Format represents a string format.
All implementations of Format provide a string representation and text marshaling/unmarshaling interface to be used by encoders (e.g. encoding/json).
type HexColor ¶
type HexColor string
HexColor represents a hex color string format.
swagger:strfmt hexcolor.
func (*HexColor) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (HexColor) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (HexColor) MarshalJSON ¶
MarshalJSON returns the HexColor as JSON.
func (HexColor) MarshalText ¶
MarshalText turns this instance into text.
func (*HexColor) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*HexColor) UnmarshalJSON ¶
UnmarshalJSON sets the HexColor from JSON.
func (*HexColor) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type Hostname ¶
type Hostname string
Hostname represents the hostname string format as specified by the json schema spec.
swagger:strfmt hostname.
func (*Hostname) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Hostname) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (Hostname) MarshalJSON ¶
MarshalJSON returns the Hostname as JSON.
func (Hostname) MarshalText ¶
MarshalText turns this instance into text.
func (*Hostname) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*Hostname) UnmarshalJSON ¶
UnmarshalJSON sets the Hostname from JSON.
func (*Hostname) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type IPv4 ¶
type IPv4 string
IPv4 represents an IP v4 address.
swagger:strfmt ipv4.
func (*IPv4) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (IPv4) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (IPv4) MarshalJSON ¶
MarshalJSON returns the IPv4 as JSON.
func (IPv4) MarshalText ¶
MarshalText turns this instance into text.
func (*IPv4) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*IPv4) UnmarshalJSON ¶
UnmarshalJSON sets the IPv4 from JSON.
func (*IPv4) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type IPv6 ¶
type IPv6 string
IPv6 represents an IP v6 address.
swagger:strfmt ipv6.
func (*IPv6) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (IPv6) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (IPv6) MarshalJSON ¶
MarshalJSON returns the IPv6 as JSON.
func (IPv6) MarshalText ¶
MarshalText turns this instance into text.
func (*IPv6) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*IPv6) UnmarshalJSON ¶
UnmarshalJSON sets the IPv6 from JSON.
func (*IPv6) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type ISBN ¶
type ISBN string
ISBN represents an isbn string format.
swagger:strfmt isbn.
func (*ISBN) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (ISBN) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (ISBN) MarshalJSON ¶
MarshalJSON returns the ISBN as JSON.
func (ISBN) MarshalText ¶
MarshalText turns this instance into text.
func (*ISBN) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*ISBN) UnmarshalJSON ¶
UnmarshalJSON sets the ISBN from JSON.
func (*ISBN) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type ISBN10 ¶
type ISBN10 string
ISBN10 represents an isbn 10 string format.
swagger:strfmt isbn10.
func (*ISBN10) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (ISBN10) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (ISBN10) MarshalJSON ¶
MarshalJSON returns the ISBN10 as JSON.
func (ISBN10) MarshalText ¶
MarshalText turns this instance into text.
func (*ISBN10) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*ISBN10) UnmarshalJSON ¶
UnmarshalJSON sets the ISBN10 from JSON.
func (*ISBN10) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type ISBN13 ¶
type ISBN13 string
ISBN13 represents an isbn 13 string format.
swagger:strfmt isbn13.
func (*ISBN13) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (ISBN13) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (ISBN13) MarshalJSON ¶
MarshalJSON returns the ISBN13 as JSON.
func (ISBN13) MarshalText ¶
MarshalText turns this instance into text.
func (*ISBN13) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*ISBN13) UnmarshalJSON ¶
UnmarshalJSON sets the ISBN13 from JSON.
func (*ISBN13) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type ISODuration ¶ added in v0.27.0
type ISODuration[P ISODurationPolicy] time.Duration
ISODuration is an ISO 8601 / RFC 3339 duration (e.g. "P1Y2M3DT4H5M6S", "P2W").
The type parameter P selects the parsing policy at compile time (see ISODurationPolicy). Every instantiation is a distinct type that round-trips through JSON, text, SQL and BSON. Use the DurationISO8601 alias for the strict, spec-compliant default.
Like time.Duration, it stores a nanosecond count; the largest representable duration is approximately 290 years. Calendar units are collapsed to fixed lengths (year = 365 days, month = 30 days), which is lossy by nature.
This generic type carries no swagger:strfmt annotation: go-swagger binds a concrete format name to the DurationISO8601 alias, not to a generic declaration.
Example (Lenient) ¶
Selecting the DurationLenient policy as the type parameter applies the relaxed grammar on the struct-decode path too — useful when consuming feeds that emit fractions or signs.
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/go-openapi/strfmt"
)
func main() {
type Config struct {
Interval strfmt.ISODuration[strfmt.DurationLenient] `json:"interval"`
}
var c Config
if err := json.Unmarshal([]byte(`{"interval":"PT0.25S"}`), &c); err != nil {
fmt.Println(err)
return
}
fmt.Println(time.Duration(c.Interval))
}
Output: 250ms
func (*ISODuration[P]) DeepCopy ¶ added in v0.27.0
func (d *ISODuration[P]) DeepCopy() *ISODuration[P]
DeepCopy copies the receiver into a new value.
func (*ISODuration[P]) DeepCopyInto ¶ added in v0.27.0
func (d *ISODuration[P]) DeepCopyInto(out *ISODuration[P])
DeepCopyInto copies the receiver into out.
func (ISODuration[P]) Equal ¶ added in v0.27.0
func (d ISODuration[P]) Equal(other ISODuration[P]) bool
Equal reports whether two durations are equal.
func (ISODuration[P]) MarshalBSON ¶ added in v0.27.0
func (d ISODuration[P]) MarshalBSON() ([]byte, error)
MarshalBSON renders the ISODuration as a BSON document.
BSON is a storage boundary (like SQL): the value is emitted losslessly with ISODuration.String, regardless of the policy P — a strict policy that could not serialize a sign or sub-second precision on the interchange path must still be persistable.
func (ISODuration[P]) MarshalJSON ¶ added in v0.27.0
func (d ISODuration[P]) MarshalJSON() ([]byte, error)
MarshalJSON returns the duration as a JSON string, applying the policy P.
func (ISODuration[P]) MarshalText ¶ added in v0.27.0
func (d ISODuration[P]) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler, applying the policy P: a strict policy errors on a value it cannot represent (see [isoEmit]).
func (*ISODuration[P]) Scan ¶ added in v0.27.0
func (d *ISODuration[P]) Scan(raw any) error
Scan reads a duration (nanoseconds) from a database driver value.
func (ISODuration[P]) String ¶ added in v0.27.0
func (d ISODuration[P]) String() string
String renders the duration in canonical ISO 8601 form.
Unlike ISODuration.MarshalText, String is a best-effort display form: it always renders the true value (lossless), even under a strict policy that could not serialize it (e.g. a sign or sub-second precision).
func (*ISODuration[P]) UnmarshalBSON ¶ added in v0.27.0
func (d *ISODuration[P]) UnmarshalBSON(data []byte) error
UnmarshalBSON reads an ISODuration from a BSON document.
The stored value is our own canonical output, so it is parsed leniently: BSON is trusted storage, not external interchange, and must round-trip whatever ISODuration.MarshalBSON emitted even under a strict policy P.
func (*ISODuration[P]) UnmarshalJSON ¶ added in v0.27.0
func (d *ISODuration[P]) UnmarshalJSON(data []byte) error
UnmarshalJSON sets the duration from a JSON string, applying the policy P.
func (*ISODuration[P]) UnmarshalText ¶ added in v0.27.0
func (d *ISODuration[P]) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler, applying the policy P.
type ISODurationOption ¶ added in v0.27.0
type ISODurationOption func(*isoDurationConfig)
ISODurationOption relaxes the strict parser on the explicit ParseISO8601Duration path, for programmatic callers.
It has no effect on the registry / struct-field decode path, which is governed by the type's policy.
func WithISOFractions ¶ added in v0.27.0
func WithISOFractions() ISODurationOption
WithISOFractions accepts a decimal fraction on the least significant component.
func WithISOLenient ¶ added in v0.27.0
func WithISOLenient() ISODurationOption
WithISOLenient relaxes every strictness knob (see DurationLenient).
func WithISORelaxedAnchoring ¶ added in v0.27.0
func WithISORelaxedAnchoring() ISODurationOption
WithISORelaxedAnchoring allows gaps in the component chain (e.g. P1Y2D, PT1H2S).
func WithISOSign ¶ added in v0.27.0
func WithISOSign() ISODurationOption
WithISOSign accepts a leading '+' or '-'.
func WithISOSpace ¶ added in v0.27.0
func WithISOSpace() ISODurationOption
WithISOSpace tolerates surrounding whitespace.
func WithISOWeekCombinable ¶ added in v0.27.0
func WithISOWeekCombinable() ISODurationOption
WithISOWeekCombinable allows the 'W' designator to combine with other components.
type ISODurationPolicy ¶ added in v0.27.0
type ISODurationPolicy interface {
// contains filtered or unexported methods
}
ISODurationPolicy is a compile-time policy selecting the parsing behaviour of an ISODuration.
It is a phantom type parameter: a zero-size value whose single method yields the parser configuration. See DurationStrict and DurationLenient.
type MAC ¶
type MAC string
MAC represents a 48 bit MAC address.
swagger:strfmt mac.
func (*MAC) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (MAC) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (MAC) MarshalJSON ¶
MarshalJSON returns the MAC as JSON.
func (MAC) MarshalText ¶
MarshalText turns this instance into text.
func (*MAC) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*MAC) UnmarshalJSON ¶
UnmarshalJSON sets the MAC from JSON.
func (*MAC) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type NameNormalizer ¶
NameNormalizer is a function that normalizes a format name.
The default duration format corresponds to "duration-human".
type ObjectId ¶
type ObjectId [12]byte //nolint:revive
ObjectId represents a BSON object ID (a 12-byte unique identifier).
swagger:strfmt bsonobjectid.
func NewObjectId ¶
NewObjectId creates a ObjectId from a hexadecimal String.
func (*ObjectId) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (ObjectId) MarshalBSON ¶ added in v0.19.2
MarshalBSON renders the object id as a BSON document.
func (ObjectId) MarshalBSONValue ¶ added in v0.19.2
MarshalBSONValue marshals the ObjectId as a raw BSON ObjectID value.
func (ObjectId) MarshalJSON ¶
MarshalJSON returns the ObjectId as JSON.
func (ObjectId) MarshalText ¶
MarshalText turns this instance into text.
func (*ObjectId) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON reads the objectId from a BSON document.
func (*ObjectId) UnmarshalBSONValue ¶ added in v0.19.2
UnmarshalBSONValue unmarshals a raw BSON ObjectID value into this ObjectId.
func (*ObjectId) UnmarshalJSON ¶
UnmarshalJSON sets the ObjectId from JSON.
func (*ObjectId) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type Password ¶
type Password string
Password represents a password.
This has no validations and is mainly used as a marker for UI components.
swagger:strfmt password.
func (*Password) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (Password) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (Password) MarshalJSON ¶
MarshalJSON returns the Password as JSON.
func (Password) MarshalText ¶
MarshalText turns this instance into text.
func (*Password) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*Password) UnmarshalJSON ¶
UnmarshalJSON sets the Password from JSON.
func (*Password) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type RGBColor ¶
type RGBColor string
RGBColor represents a RGB color string format.
swagger:strfmt rgbcolor.
func (*RGBColor) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (RGBColor) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (RGBColor) MarshalJSON ¶
MarshalJSON returns the RGBColor as JSON.
func (RGBColor) MarshalText ¶
MarshalText turns this instance into text.
func (*RGBColor) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*RGBColor) UnmarshalJSON ¶
UnmarshalJSON sets the RGBColor from JSON.
func (*RGBColor) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type Registry ¶
type Registry interface {
Add(name string, strfmt Format, validator Validator) bool
DelByName(name string) bool
GetType(name string) (reflect.Type, bool)
ContainsName(name string) bool
Validates(name, data string) bool
Parse(name, data string) (any, error)
MapStructureHookFunc() mapstructure.DecodeHookFunc
}
Registry is a registry of string formats, with a validation method.
var Default Registry //nolint:gochecknoglobals // package-level default registry, by design
Default is the default formats registry.
NOTE: format "duration" is wire by default onto "duration-human".
var JSONSchema2020Registry Registry //nolint:gochecknoglobals // package-level default registry, by design
JSONSchema2020Registry is the format registry with JSONSchema draft 2020 formats (e.g. duration is an iso8601 duration).
func NewFormats ¶
func NewFormats() Registry
NewFormats creates a new formats registry seeded with the values from the default.
func NewSeededFormats ¶
func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry
NewSeededFormats creates a new formats registry.
type SSN ¶
type SSN string
SSN represents a social security string format.
swagger:strfmt ssn.
func (*SSN) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (SSN) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (SSN) MarshalJSON ¶
MarshalJSON returns the SSN as JSON.
func (SSN) MarshalText ¶
MarshalText turns this instance into text.
func (*SSN) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*SSN) UnmarshalJSON ¶
UnmarshalJSON sets the SSN from JSON.
func (*SSN) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type ULID ¶ added in v0.20.1
ULID represents a ulid string format.
Reference ¶
https://github.com/ulid/spec
Implementation ¶
https://github.com/oklog/ulid
swagger:strfmt ulid.
func NewULIDZero ¶ added in v0.20.1
func NewULIDZero() ULID
NewULIDZero returns a zero valued ULID type.
func (*ULID) DeepCopyInto ¶ added in v0.20.1
DeepCopyInto copies the receiver and writes its value into out.
func (ULID) Equal ¶ added in v0.20.1
Equal checks if two ULID instances are equal by their underlying type.
func (ULID) MarshalBSON ¶ added in v0.20.1
MarshalBSON document from this value.
func (ULID) MarshalBinary ¶ added in v0.20.1
MarshalBinary implements the encoding.encoding.BinaryMarshaler interface.
func (ULID) MarshalJSON ¶ added in v0.20.1
MarshalJSON returns the ULID as JSON.
func (ULID) MarshalText ¶ added in v0.20.1
MarshalText returns this instance into text.
func (*ULID) UnmarshalBSON ¶ added in v0.20.1
UnmarshalBSON document into this value.
func (*ULID) UnmarshalBinary ¶ added in v0.20.1
UnmarshalBinary implements the encoding.encoding.BinaryUnmarshaler interface.
func (*ULID) UnmarshalJSON ¶ added in v0.20.1
UnmarshalJSON sets the ULID from JSON.
func (*ULID) UnmarshalText ¶ added in v0.20.1
UnmarshalText hydrates this instance from text.
type URI ¶
type URI string
URI represents the uri string format as specified by the json schema spec.
swagger:strfmt uri.
func (*URI) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (URI) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (URI) MarshalJSON ¶
MarshalJSON returns the URI as JSON.
func (URI) MarshalText ¶
MarshalText turns this instance into text.
func (*URI) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*URI) UnmarshalJSON ¶
UnmarshalJSON sets the URI from JSON.
func (*URI) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type UUID ¶
type UUID string
UUID represents a uuid string format.
swagger:strfmt uuid.
func (*UUID) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (UUID) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (UUID) MarshalJSON ¶
MarshalJSON returns the UUID as JSON.
func (UUID) MarshalText ¶
MarshalText turns this instance into text.
func (*UUID) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON sets the UUID from JSON.
func (*UUID) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type UUID3 ¶
type UUID3 string
UUID3 represents a uuid3 string format.
swagger:strfmt uuid3.
func (*UUID3) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (UUID3) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (UUID3) MarshalJSON ¶
MarshalJSON returns the UUID3 as JSON.
func (UUID3) MarshalText ¶
MarshalText turns this instance into text.
func (*UUID3) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*UUID3) UnmarshalJSON ¶
UnmarshalJSON sets the UUID3 from JSON.
func (*UUID3) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type UUID4 ¶
type UUID4 string
UUID4 represents a uuid4 string format.
swagger:strfmt uuid4.
func (*UUID4) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (UUID4) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (UUID4) MarshalJSON ¶
MarshalJSON returns the UUID4 as JSON.
func (UUID4) MarshalText ¶
MarshalText turns this instance into text.
func (*UUID4) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*UUID4) UnmarshalJSON ¶
UnmarshalJSON sets the UUID4 from JSON.
func (*UUID4) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type UUID5 ¶
type UUID5 string
UUID5 represents a uuid5 string format.
swagger:strfmt uuid5.
func (*UUID5) DeepCopyInto ¶ added in v0.19.0
DeepCopyInto copies the receiver and writes its value into out.
func (UUID5) MarshalBSON ¶ added in v0.19.2
MarshalBSON document from this value.
func (UUID5) MarshalJSON ¶
MarshalJSON returns the UUID5 as JSON.
func (UUID5) MarshalText ¶
MarshalText turns this instance into text.
func (*UUID5) UnmarshalBSON ¶ added in v0.19.2
UnmarshalBSON document into this value.
func (*UUID5) UnmarshalJSON ¶
UnmarshalJSON sets the UUID5 from JSON.
func (*UUID5) UnmarshalText ¶
UnmarshalText hydrates this instance from text.
type UUID7 ¶ added in v0.25.0
type UUID7 string
UUID7 represents a uuid7 string format.
swagger:strfmt uuid7.
func (*UUID7) DeepCopyInto ¶ added in v0.25.0
DeepCopyInto copies the receiver and writes its value into out.
func (UUID7) MarshalBSON ¶ added in v0.25.0
MarshalBSON document from this value.
func (UUID7) MarshalJSON ¶ added in v0.25.0
MarshalJSON returns the UUID7 as JSON.
func (UUID7) MarshalText ¶ added in v0.25.0
MarshalText turns this instance into text.
func (*UUID7) UnmarshalBSON ¶ added in v0.25.0
UnmarshalBSON document into this value.
func (*UUID7) UnmarshalJSON ¶ added in v0.25.0
UnmarshalJSON sets the UUID7 from JSON.
func (*UUID7) UnmarshalText ¶ added in v0.25.0
UnmarshalText hydrates this instance from text.