go-openapi/strfmt

GitHub: go-openapi/strfmt

该项目为 Go 语言的 OpenAPI 工具链提供了一套通用的强类型字符串格式定义,支持 JSON、SQL 和 BSON 的序列化与校验。

Stars: 111 | Forks: 68

# strfmt [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/cas/db/dbc20fbb5b43d751115743b728bc221bb9cb0a7c6247701ddba81ac8c7acc81e.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/cas/f3/f38b970f8dc114adca53ef9669122f3bf5a0a92b76f1cededc8e5af7f9b597c7.svg)][vuln-scan-url] [![CodeQL](https://static.pigsec.cn/wp-content/uploads/repos/cas/53/539e9a6bf48ad24469a4363bff3aa68124154549e26592783d3d8577f2acbbfc.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) ## 公告 * **2026-03-07** : v0.26.0 **移除了对 mongodb driver 的依赖** * mongodb 用户仍然可以毫无改变地使用此包 * 然而,我们已经冻结了在 v2.5.0 版本中对 mongodb driver 的向后兼容支持 * 希望跟上此 driver 未来演进(可能不兼容)的用户 可以通过在他们的程序中添加一个空白导入来实现:`import _ "github.com/go-openapi/strfmt/enable/mongodb"`。 这会将行为切换到实际的 driver,该 driver 作为独立的模块定期更新。 ## 状态 API 已稳定。 ## 在您的项目中导入此库 ``` go get github.com/go-openapi/strfmt ``` ## 内容 `strfmt` 表示一种众所周知的字符串格式,例如 hostname 或 email。 此包提供了一些额外的格式,例如(美国)信用卡、颜色等。 格式类型可以对 JSON 进行序列化和反序列化,或者与 SQL 数据库进行交互。 同时也支持 BSON (MongoDB)。 ### 支持的格式 `go-openapi/strfmt` 遵循 swagger 2.0 规范,其中包含以下格式 定义在[此处](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types)。 它还为 go-openapi 用户提供了便捷的扩展。 - [x] JSON-schema draft 4 格式 - date-time - email - hostname - ipv4 - ipv6 - uri - [x] swagger 2.0 格式扩展 - binary - byte (例如:base64 编码的字符串) - date (例如:"1970-01-01") - password - [x] go-openapi 自定义格式扩展 - bsonobjectid (BSON objectID) - creditcard - duration (例如:"3 weeks", "1ms") - hexcolor (例如:"#FFFFFF") - isbn, isbn10, isbn13 - mac (例如 "01:02:03:04:05:06") - rgbcolor (例如:"rgb(100,100,100)") - ssn - uuid, uuid3, uuid4, uuid5, uuid7 - cidr (例如:"192.0.2.1/24", "2001:db8:a0b:12f0::1/32") - ulid (例如:"00000PP9HGSBSSDZ1JTEXBJ0PW", [规范](https://github.com/ulid/spec)) ### 类型转换 这里定义的所有类型都实现了 stringer 接口,并且可以通过 `.String()` 转换为字符串。 请注意,此包定义的大多数类型都可以直接转换为字符串,例如 `string(Email{})`。 `Date` 和 `DateTime` 可以直接转换为 `time.Time`,例如 `time.Time(Time{})`。 同样地,您可以将 `Duration` 转换为 `time.Duration`,例如 `time.Duration(Duration{})` ### 使用指针 `conv` 子包提供了在这些类型与指针之间进行转换的辅助函数,就像 `go-openapi/swag` 处理基本类型那样。 ### 格式类型 在 `strfmt` 中定义的类型提供了序列化和验证能力。 已定义的类型列表: - 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) ## 更新日志 参见 ## 参考 ## 许可协议 本库基于 [SPDX-License-Identifier: Apache-2.0](./LICENSE) 协议发布。 ## 其他文档 ## 发布新版本 维护者可以通过以下任一方式发布新版本: * 运行[此 workflow](https://github.com/go-openapi/strfmt/actions/workflows/bump-release.yml) * 或推送一个 semver 标签 * 推荐使用签名标签 * 标签信息将被前置到发布说明中
标签:EVTX分析, Go, OpenAPI, Ruby工具, Swagger, 序列化, 开源工具库, 数据格式, 日志审计