Skip to content

proposal: extend netip.Addr support to ipv6#792

Merged
wolveix merged 4 commits intodanielgtaylor:mainfrom
costela:add-support-for-dualstack-ip-parsing
Feb 16, 2026
Merged

proposal: extend netip.Addr support to ipv6#792
wolveix merged 4 commits intodanielgtaylor:mainfrom
costela:add-support-for-dualstack-ip-parsing

Conversation

@costela
Copy link
Copy Markdown
Contributor

@costela costela commented Apr 8, 2025

netip.Addr supports parsing both ipv4 and ipv6 out of the box. So it is a bit surprising to have a netip.Addr field in an API only support ipv4 and no easy way to add "dual-stack" support for APIs.

I propose to extend the support for netip.Addr added in #396 and support ipv6 out of the box as well.

⚠️ The change in the format detection for netip.Addr fields may be considered breaking, since existing APIs will start accepting IPv6 addresses and people may be counting on that limitation. I'd argue that it's worth it, but if not, we can remove that single change, while still adding support for the ip dual-stack format, to be used explicitly.

WDYT?

Copilot AI review requested due to automatic review settings April 8, 2025 15:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (ce59480) to head (20d3402).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #792   +/-   ##
=======================================
  Coverage   92.92%   92.93%           
=======================================
  Files          23       23           
  Lines        4636     4642    +6     
=======================================
+ Hits         4308     4314    +6     
  Misses        271      271           
  Partials       57       57           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@costela
Copy link
Copy Markdown
Contributor Author

costela commented Apr 13, 2025

Taking a second look at this, it appears it is possible to support dual-stack input by setting format:"ipv6", because IP.To16 also works for ipv4.

That doesn't seem very intuitive and could maybe warrant a doc fix?

Personally I'd try making this a bit more explicit: the ipv4/ipv6 formats should really be specific to their respective IP versions, and a new ip format should support both. WDYT?

Also, it may be a good idea to switch to netip for all validations regardless, just for the micro-optimization:

pkg: github.com/danielgtaylor/huma/v2
cpu: 12th Gen Intel(R) Core(TM) i7-1250U
BenchmarkNetParseIP-12               31314682                32.42 ns/op           16 B/op          1 allocs/op
BenchmarkNetipParseAddr-12           72398744                15.65 ns/op            0 B/op          0 allocs/op

Comment thread validate.go Outdated
@costela costela force-pushed the add-support-for-dualstack-ip-parsing branch from 896acfb to b8026a4 Compare August 29, 2025 08:00
@thushjandan
Copy link
Copy Markdown

Would be awesome if this PR could be merged

@wolveix wolveix merged commit 1c5f812 into danielgtaylor:main Feb 16, 2026
4 checks passed
@wolveix
Copy link
Copy Markdown
Collaborator

wolveix commented Feb 16, 2026

Awesome work, thanks so much @costela! Sorry this sat for so long :)

@costela costela deleted the add-support-for-dualstack-ip-parsing branch February 21, 2026 09:38
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.

5 participants