• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H19-Aug-2021-

conv/H19-Aug-2021-

hack/H19-Aug-2021-

.editorconfigH A D19-Aug-2021539

.gitignoreH A D19-Aug-202125

.golangci.ymlH A D19-Aug-2021709

.travis.ymlH A D19-Aug-20211.3 KiB

CODE_OF_CONDUCT.mdH A D19-Aug-20213.2 KiB

LICENSEH A D19-Aug-202111.1 KiB

README.mdH A D19-Aug-20213.1 KiB

bson.goH A D19-Aug-20214.4 KiB

bson_test.goH A D19-Aug-20211.6 KiB

date.goH A D19-Aug-20214.2 KiB

date_test.goH A D19-Aug-20214.4 KiB

default.goH A D19-Aug-202146 KiB

default_test.goH A D19-Aug-202118.4 KiB

doc.goH A D19-Aug-2021730

duration.goH A D19-Aug-20214.9 KiB

duration_test.goH A D19-Aug-20215.4 KiB

format.goH A D19-Aug-20218 KiB

format_test.goH A D19-Aug-20218.3 KiB

go.modH A D19-Aug-2021341

go.sumH A D19-Aug-202112.6 KiB

time.goH A D19-Aug-20218.5 KiB

time_test.goH A D19-Aug-20219.3 KiB

ulid.goH A D19-Aug-20214.9 KiB

ulid_test.goH A D19-Aug-20218 KiB

README.md

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  - ulid (e.g. "00000PP9HGSBSSDZ1JTEXBJ0PW", [spec](https://github.com/ulid/spec))
42
43> NOTE: as the name stands for, this package is intended to support string formatting only.
44> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
45> "integer" (e.g. float, double, int32...).
46
47## Type conversion
48
49All types defined here are stringers and may be converted to strings with `.String()`.
50Note that most types defined by this package may be converted directly to string like `string(Email{})`.
51
52`Date` and `DateTime` may be converted directly to `time.Time` like `time.Time(Time{})`.
53Similarly, you can convert `Duration` to `time.Duration` as in `time.Duration(Duration{})`
54
55## Using pointers
56
57The `conv` subpackage provides helpers to convert the types to and from pointers, just like `go-openapi/swag` does
58with primitive types.
59
60## Format types
61Types defined in strfmt expose marshaling and validation capabilities.
62
63List of defined types:
64- Base64
65- CreditCard
66- Date
67- DateTime
68- Duration
69- Email
70- HexColor
71- Hostname
72- IPv4
73- IPv6
74- CIDR
75- ISBN
76- ISBN10
77- ISBN13
78- MAC
79- ObjectId
80- Password
81- RGBColor
82- SSN
83- URI
84- UUID
85- UUID3
86- UUID4
87- UUID5
88- [ULID](https://github.com/ulid/spec)
89