...

Text file src/github.com/go-openapi/strfmt/README.md

Documentation: github.com/go-openapi/strfmt

     1# Strfmt [![Build Status](https://github.com/go-openapi/strfmt/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/strfmt/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/strfmt)
     2[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
     3[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/strfmt/master/LICENSE)
     4[![GoDoc](https://godoc.org/github.com/go-openapi/strfmt?status.svg)](http://godoc.org/github.com/go-openapi/strfmt)
     5[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)](https://goreportcard.com/report/github.com/go-openapi/strfmt)
     6
     7This package exposes a registry of data types to support string formats in the go-openapi toolkit.
     8
     9strfmt represents a well known string format such as credit card or email. The go toolkit for OpenAPI specifications knows how to deal with those.
    10
    11## Supported data formats
    12go-openapi/strfmt follows the swagger 2.0 specification with the following formats
    13defined [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types).
    14
    15It also provides convenient extensions to go-openapi users.
    16
    17- [x] JSON-schema draft 4 formats
    18  - date-time
    19  - email
    20  - hostname
    21  - ipv4
    22  - ipv6
    23  - uri
    24- [x] swagger 2.0 format extensions
    25  - binary
    26  - byte (e.g. base64 encoded string)
    27  - date (e.g. "1970-01-01")
    28  - password
    29- [x] go-openapi custom format extensions
    30  - bsonobjectid (BSON objectID)
    31  - creditcard
    32  - duration (e.g. "3 weeks", "1ms")
    33  - hexcolor (e.g. "#FFFFFF")
    34  - isbn, isbn10, isbn13
    35  - mac (e.g "01:02:03:04:05:06")
    36  - rgbcolor (e.g. "rgb(100,100,100)")
    37  - ssn
    38  - uuid, uuid3, uuid4, uuid5
    39  - cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32")
    40  - ulid (e.g. "00000PP9HGSBSSDZ1JTEXBJ0PW", [spec](https://github.com/ulid/spec))
    41
    42> NOTE: as the name stands for, this package is intended to support string formatting only.
    43> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
    44> "integer" (e.g. float, double, int32...).
    45
    46## Type conversion
    47
    48All types defined here are stringers and may be converted to strings with `.String()`.
    49Note that most types defined by this package may be converted directly to string like `string(Email{})`.
    50
    51`Date` and `DateTime` may be converted directly to `time.Time` like `time.Time(Time{})`.
    52Similarly, you can convert `Duration` to `time.Duration` as in `time.Duration(Duration{})`
    53
    54## Using pointers
    55
    56The `conv` subpackage provides helpers to convert the types to and from pointers, just like `go-openapi/swag` does
    57with primitive types.
    58
    59## Format types
    60Types defined in strfmt expose marshaling and validation capabilities.
    61
    62List of defined types:
    63- Base64
    64- CreditCard
    65- Date
    66- DateTime
    67- Duration
    68- Email
    69- HexColor
    70- Hostname
    71- IPv4
    72- IPv6
    73- CIDR
    74- ISBN
    75- ISBN10
    76- ISBN13
    77- MAC
    78- ObjectId
    79- Password
    80- RGBColor
    81- SSN
    82- URI
    83- UUID
    84- UUID3
    85- UUID4
    86- UUID5
    87- [ULID](https://github.com/ulid/spec)

View as plain text