1# Strfmt [![Build Status](https://travis-ci.org/go-openapi/strfmt.svg?branch=master)](https://travis-ci.org/go-openapi/strfmt) [![codecov](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/strfmt) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) 2 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[![GolangCI](https://golangci.com/badges/github.com/go-openapi/strfmt.svg)](https://golangci.com) 6[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)](https://goreportcard.com/report/github.com/go-openapi/strfmt) 7 8This package exposes a registry of data types to support string formats in the go-openapi toolkit. 9 10strfmt represents a well known string format such as credit card or email. The go toolkit for OpenAPI specifications knows how to deal with those. 11 12## Supported data formats 13go-openapi/strfmt follows the swagger 2.0 specification with the following formats 14defined [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types). 15 16It also provides convenient extensions to go-openapi users. 17 18- [x] JSON-schema draft 4 formats 19 - date-time 20 - email 21 - hostname 22 - ipv4 23 - ipv6 24 - uri 25- [x] swagger 2.0 format extensions 26 - binary 27 - byte (e.g. base64 encoded string) 28 - date (e.g. "1970-01-01") 29 - password 30- [x] go-openapi custom format extensions 31 - bsonobjectid (BSON objectID) 32 - creditcard 33 - duration (e.g. "3 weeks", "1ms") 34 - hexcolor (e.g. "#FFFFFF") 35 - isbn, isbn10, isbn13 36 - mac (e.g "01:02:03:04:05:06") 37 - rgbcolor (e.g. "rgb(100,100,100)") 38 - ssn 39 - uuid, uuid3, uuid4, uuid5 40 - cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32") 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