Conversation
…ing; add tests for IPv6 functions
… improve README examples and add benchmarks for IPv6 conversions
There was a problem hiding this comment.
Pull request overview
This PR updates the ipconv Go library to improve conversion reliability (especially around IPv6 error handling), reduce allocations in hot paths, and refresh documentation/tests and Go/CI versioning.
Changes:
- Harden IPv6 conversion functions against
nil/invalidnet.IPinputs and adjust error messages. - Reduce allocations in
IntToIPv6and simplifyBigIntToIPv6implementation. - Update README example, add error-path tests + benchmarks, and bump the module Go version / CI matrix.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Fixes the example to correctly branch on ParseIP success and avoid unused imports. |
| ipconv.go | Updates error strings, improves IPv4/IPv6 conversions, and changes ParseIP’s version detection logic. |
| ipconv_test.go | Adds IPv6 error-path tests and benchmarks for IPv6 conversion functions. |
| go.mod | Bumps the module’s go directive to 1.22. |
| CHANGELOG.md | Adds a v1.3.0 entry describing the changes. |
| .github/workflows/ipconv-test.yml | Updates the Go version test matrix and normalizes step indentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+19
to
22
| if err == nil && version == 4 { | ||
| val, _ := ipconv.IPv4ToInt(ip) | ||
| fmt.Println(val) | ||
| } |
| strategy: | ||
| matrix: | ||
| go-version: [1.18.x, 1.20.x, 1.22.x] | ||
| go-version: [1.22.x, 1.23.x] |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and fixes to the
ipconvlibrary, focusing on error handling, performance optimizations, and compatibility updates. The changes enhance the reliability of IPv6 conversion functions, optimize memory usage, correct error messages, and update the project for newer Go versions. Tests and documentation have also been updated to reflect these improvements.Core improvements and bug fixes:
IPv6ToIntandIPv6ToBigIntto properly handleniland invalid IP addresses, preventing possible panics. [1] [2] [3]ErrNotIPv4AddressandErrNotIPv6Address(typo correction: "addres" → "address").IPv4ToIntto cache the result ofTo4()to avoid redundant computation.IntToIPv6to write directly to the target slice, reducing allocations.BigIntToIPv6to usebig.Int.FillBytesfor cleaner and more efficient conversion.Go version and CI updates:
go.modand adjusted the GitHub Actions workflow to test against Go 1.21, 1.22, and 1.23. [1] [2]Documentation and testing:
README.mdto compile and run correctly.IntToIPv6andBigIntToIPv6. [1] [2]