go-openapi/strfmt

GitHub: go-openapi/strfmt

Stars: 111 | Forks: 66

# strfmt [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/1b2aad39f1022316.svg)][test-url] [![Coverage](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)][cov-url] [![CI vuln scan](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/1d2f115f4e022317.svg)][vuln-scan-url] [![CodeQL](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/9837597b85022318.svg)][codeql-url] [![Release](https://badge.fury.io/gh/go-openapi%2Fstrfmt.svg)][release-url] [![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)][gocard-url] [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/go-openapi/strfmt)][codefactor-url] [![License](http://img.shields.io/badge/license-Apache%20v2-orange.svg)][license-url] [![GoDoc](https://pkg.go.dev/badge/github.com/go-openapi/strfmt)][godoc-url] [![Discord Channel](https://img.shields.io/discord/1446918742398341256?logo=discord&label=discord&color=blue)][discord-url] [![go version](https://img.shields.io/github/go-mod/go-version/go-openapi/strfmt)][goversion-url] ![Top language](https://img.shields.io/github/languages/top/go-openapi/strfmt) ![Commits since latest release](https://img.shields.io/github/commits-since/go-openapi/strfmt/latest) ## Announcements * **2026-03-07** : v0.26.0 **dropped dependency to the mongodb driver** * mongodb users can still use this package without any change * however, we have frozen the back-compatible support for mongodb driver at v2.5.0 * users who want to keep-up with future evolutions (possibly incompatible) of this driver can do so by adding a blank import in their program: `import _ "github.com/go-openapi/strfmt/enable/mongodb"`. This will switch the behavior to the actual driver, which remains regularly updated as an independent module. ## Status API is stable. ## Import this library in your project go get github.com/go-openapi/strfmt ## Contents `strfmt` represents a well known string format such as hostname or email. This package provides a few extra formats such as credit card (US), color, etc. Format types can serialize and deserialize JSON or from a SQL database. BSON is also supported (MongoDB). ### Supported formats `go-openapi/strfmt` follows the swagger 2.0 specification with the following formats defined [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types). It also provides convenient extensions to go-openapi users. - [x] JSON-schema draft 4 formats - date-time - email - hostname - ipv4 - ipv6 - uri - [x] swagger 2.0 format extensions - binary - byte (e.g. base64 encoded string) - date (e.g. "1970-01-01") - password - [x] 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, uuid7 - cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32") - ulid (e.g. "00000PP9HGSBSSDZ1JTEXBJ0PW", [spec](https://github.com/ulid/spec)) ### 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](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-3) - [UUID4](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-4) - [UUID5](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-5) - [UUID7](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-7) - [ULID](https://github.com/ulid/spec) ## Change log See ## References ## Licensing This library ships under the [SPDX-License-Identifier: Apache-2.0](./LICENSE). ## Other documentation ## Cutting a new release Maintainers can cut a new release by either: * running [this workflow](https://github.com/go-openapi/strfmt/actions/workflows/bump-release.yml) * or pushing a semver tag * signed tags are preferred * The tag message is prepended to release notes
标签:EVTX分析