Skip to content

🔥 Add IsIPv4/v6 util#32

Merged
jozsefsallai merged 2 commits intogofiber:masterfrom
sadfun:master
Oct 17, 2022
Merged

🔥 Add IsIPv4/v6 util#32
jozsefsallai merged 2 commits intogofiber:masterfrom
sadfun:master

Conversation

@sadfun
Copy link
Contributor

@sadfun sadfun commented Oct 17, 2022

Adding utils (and tests) for IP addresses validation. Used in #2168.

goos: darwin
goarch: amd64
pkg: github.com/gofiber/utils
cpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Benchmark_IsIPv4
Benchmark_IsIPv4/fiber
Benchmark_IsIPv4/fiber-12         	39321841	        30.89 ns/op	       0 B/op	       0 allocs/op
Benchmark_IsIPv4/default
Benchmark_IsIPv4/default-12       	15759016	        71.90 ns/op	      16 B/op	       1 allocs/op
Benchmark_IsIPv6
Benchmark_IsIPv6/fiber
Benchmark_IsIPv6/fiber-12         	11728011	       101.5 ns/op	       0 B/op	       0 allocs/op
Benchmark_IsIPv6/default
Benchmark_IsIPv6/default-12       	 7560738	       157.5 ns/op	      16 B/op	       1 allocs/op

Copy link
Member

@jozsefsallai jozsefsallai left a comment

Choose a reason for hiding this comment

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

Just a small nitpick regarding the phrasing of the comment. If you can change this according to the suggestion and the workflow runs will succeed, I can merge this

ips.go Outdated
Comment on lines +5 to +6
// IsIPv4 is plagiarism of net.ParseIP,
// but without check for IPv6 case and without returning net.IP slice, whereby IsIPv4 makes no allocations.
Copy link
Member

Choose a reason for hiding this comment

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

"plagiarism" feels like too strong of a word, maybe reword the comment to say

// IsIPv4 is a copy of the standard net.ParseIP function but without special checks
// for IPv6 and without returning a net.IP slice, thus resulting in no allocations.

same for IsIPv6

ips.go Outdated
Comment on lines +43 to +44
// IsIPv6 is plagiarism of net.ParseIP,
// but without check for IPv4 case and without returning net.IP slice, whereby IsIPv6 makes no allocations.
Copy link
Member

Choose a reason for hiding this comment

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

Same as before

@jozsefsallai
Copy link
Member

Also the linter warning

ips.go:36:2: S1008: should use 'return len(s) == 0' instead of 'if len(s) != 0 { return false }; return true' (gosimple)

@jozsefsallai jozsefsallai merged commit 8898e89 into gofiber:master Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants