Categorygithub.com/go-openapi/strfmt
modulepackage
0.23.0
Repository: https://github.com/go-openapi/strfmt.git
Documentation: pkg.go.dev

# README

Strfmt Build Status codecov

Slack Status license GoDoc Go Report Card

This package exposes a registry of data types to support string formats in the go-openapi toolkit.

strfmt represents a well known string format such as credit card or email. The go toolkit for OpenAPI specifications knows how to deal with those.

Supported data formats

go-openapi/strfmt follows the swagger 2.0 specification with the following formats defined here.

It also provides convenient extensions to go-openapi users.

  • JSON-schema draft 4 formats
    • date-time
    • email
    • hostname
    • ipv4
    • ipv6
    • uri
  • swagger 2.0 format extensions
    • binary
    • byte (e.g. base64 encoded string)
    • date (e.g. "1970-01-01")
    • password
  • go-openapi custom format extensions
    • bsonobjectid (BSON objectID)
    • creditcard
    • duration (e.g. "3 weeks", "1ms")
    • hexcolor (e.g. "#FFFFFF")
    • isbn, isbn10, isbn13
    • mac (e.g "01:02:03:04:05:06")
    • rgbcolor (e.g. "rgb(100,100,100)")
    • ssn
    • uuid, uuid3, uuid4, uuid5
    • cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32")
    • ulid (e.g. "00000PP9HGSBSSDZ1JTEXBJ0PW", spec)

NOTE: as the name stands for, this package is intended to support string formatting only. It does not provide validation for numerical values with swagger format extension for JSON types "number" or "integer" (e.g. float, double, int32...).

Type conversion

All types defined here are stringers and may be converted to strings with .String(). Note that most types defined by this package may be converted directly to string like string(Email{}).

Date and DateTime may be converted directly to time.Time like time.Time(Time{}). Similarly, you can convert Duration to time.Duration as in time.Duration(Duration{})

Using pointers

The conv subpackage provides helpers to convert the types to and from pointers, just like go-openapi/swag does with primitive types.

Format types

Types defined in strfmt expose marshaling and validation capabilities.

List of defined types:

  • Base64
  • CreditCard
  • Date
  • DateTime
  • Duration
  • Email
  • HexColor
  • Hostname
  • IPv4
  • IPv6
  • CIDR
  • ISBN
  • ISBN10
  • ISBN13
  • MAC
  • ObjectId
  • Password
  • RGBColor
  • SSN
  • URI
  • UUID
  • UUID3
  • UUID4
  • UUID5
  • ULID

# Packages

No description provided by the author

# Functions

DefaultNameNormalizer removes all dashes.
IsBSONObjectID returns true when the string is a valid BSON.ObjectId.
IsDate returns true when the string is a valid date.
IsDateTime returns true when the string is a valid date-time.
IsDuration returns true if the provided string is a valid duration.
IsEmail validates an email address.
IsHostname returns true when the string is a valid hostname.
IsULID checks if provided string is ULID format Be noticed that this function considers overflowed ULID as non-ulid.
IsUUID returns true is the string matches a UUID (in any version, including v6 and v7), upper case is allowed.
IsUUID3 returns true is the string matches a UUID v3, upper case is allowed.
IsUUID4 returns true is the string matches a UUID v4, upper case is allowed.
IsUUID5 returns true is the string matches a UUID v5, upper case is allowed.
NewDateTime is a representation of zero value for DateTime type.
NewFormats creates a new formats registry seeded with the values from the default.
NewObjectId creates a ObjectId from a Hex String.
NewSeededFormats creates a new formats registry.
NewULID generates new unique ULID value and a error if any.
NewULIDZero returns a zero valued ULID type.
ParseDateTime parses a string that represents an ISO8601 time or a unix epoch.
ParseDuration parses a duration from a string, compatible with scala duration syntax.
ParseULID parses a string that represents an valid ULID.

# Constants

DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6.
HostnamePattern http://json-schema.org/latest/json-schema-validation.html#anchor114 A string instance is valid against this attribute if it is a valid representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
ISO8601LocalTime represents a ISO8601 format to ISO8601 in local time (no timezone).
ISO8601TimeUniversalSortableDateTimePattern represents a ISO8601 universal sortable date time pattern.
short form of ISO8601TimeUniversalSortableDateTimePattern.
ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision (dropped secs).
ISO8601TimeWithReducedPrecisionLocaltime represents a ISO8601 format with reduced precision and no timezone (dropped seconds + no timezone).
RFC3339FullDate represents a full-date as specified by RFC3339 See: http://goo.gl/xXOvVd.
RFC3339Micro represents a ISO8601 format to micro instead of to nano.
RFC3339MicroNoColon represents a ISO8601 format to micro instead of to nano.
RFC3339Millis represents a ISO8601 format to millis instead of to nanos.
RFC3339MillisNoColon represents a ISO8601 format to millis instead of to nanos.
UUID3Pattern Regex for UUID3 that allows uppercase Deprecated: strfmt no longer uses regular expressions to validate UUIDs.
UUID4Pattern Regex for UUID4 that allows uppercase Deprecated: strfmt no longer uses regular expressions to validate UUIDs.
UUID5Pattern Regex for UUID5 that allows uppercase Deprecated: strfmt no longer uses regular expressions to validate UUIDs.
UUIDPattern Regex for UUID that allows uppercase Deprecated: strfmt no longer uses regular expressions to validate UUIDs.

# Variables

DateTimeFormats is the collection of formats used by ParseDateTime().
Default is the default formats registry.
DefaultTimeLocation provides a location for a time when the time zone is not encoded in the string (ex: ISO8601 Local variants).
MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds).
NormalizeTimeForMarshal provides a normalization function on time befeore marshalling (e.g.
No description provided by the author
ULIDScanOverrideFunc allows you to override the Scan method of the ULID type.
No description provided by the author
ULIDValueOverrideFunc allows you to override the Value method of the ULID type.
UnixZero sets the zero unix timestamp we want to compare against.

# Structs

ULID represents a ulid string format ref: https://github.com/ulid/spec impl: https://github.com/oklog/ulid swagger:strfmt ulid.

# Interfaces

Format represents a string format.
Registry is a registry of string formats, with a validation method.

# Type aliases

Base64 represents a base64 encoded string, using URLEncoding alphabet swagger:strfmt byte.
CIDR represents a Classless Inter-Domain Routing notation swagger:strfmt cidr.
CreditCard represents a credit card string format swagger:strfmt creditcard.
Date represents a date from the API swagger:strfmt date.
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.
Duration represents a duration Duration stores a period of time as a nanosecond count, with the largest repesentable duration being approximately 290 years.
Email represents the email string format as specified by the json schema spec swagger:strfmt email.
HexColor represents a hex color string format swagger:strfmt hexcolor.
Hostname represents the hostname string format as specified by the json schema spec swagger:strfmt hostname.
IPv4 represents an IP v4 address swagger:strfmt ipv4.
IPv6 represents an IP v6 address swagger:strfmt ipv6.
ISBN represents an isbn string format swagger:strfmt isbn.
ISBN10 represents an isbn 10 string format swagger:strfmt isbn10.
ISBN13 represents an isbn 13 string format swagger:strfmt isbn13.
MAC represents a 48 bit MAC address swagger:strfmt mac.
NameNormalizer is a function that normalizes a format name.
ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID) swagger:strfmt bsonobjectid.
Password represents a password.
RGBColor represents a RGB color string format swagger:strfmt rgbcolor.
SSN represents a social security string format swagger:strfmt ssn.
URI represents the uri string format as specified by the json schema spec swagger:strfmt uri.
UUID represents a uuid string format swagger:strfmt uuid.
UUID3 represents a uuid3 string format swagger:strfmt uuid3.
UUID4 represents a uuid4 string format swagger:strfmt uuid4.
UUID5 represents a uuid5 string format swagger:strfmt uuid5.
Validator represents a validator for a string format.