这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@danielgtaylor
Copy link
Owner

This PR makes the CBOR format optional in Huma's default config, removing the hard dependency and providing more flexibility in how default formats are set up. Technically this is not a breaking change, just a change in how defaults work, however existing users who wish to continue using CBOR must add a new import. If you set up your own config you are unaffected.

  • Moves CBOR support into github.com/danielgtaylor/huma/v2/formats/cbor
  • Creates a huma.DefaultFormats map which packages can modify. This is used by huma.DefaultConfig(...).
  • Uses the init() function to modify the default formats map when the cbor package is imported. This is similar to how the standard library works and described in Effective Go, e.g. see net/http/pprof or the crypto or sql stdlib packages.
  • Updates docs & examples

After this change, using Huma to build an API supporting JSON with the Go 1.22 http.ServeMux has zero hard dependencies.

Copy link
Contributor

@victoraugustolls victoraugustolls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really liked the approach, LGTM!

@x-user
Copy link
Contributor

x-user commented Apr 12, 2024

LGTM.

@danielgtaylor danielgtaylor merged commit 00fc8c3 into main Apr 15, 2024
@danielgtaylor danielgtaylor deleted the cbor-optional branch April 15, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants