FAQ
Hi,

In many software projects I have to get the address family of a net.IP
object. I always duplicate the following code:

func isIPv4(ip net.IP) bool {
     return len(ip) == net.IPv4len || (len(ip) > 11 && isZeros(ip[0:10]) &&
ip[10] == 0xff && ip[11] == 0xff)
}

func isZeros(ip net.IP) bool {
     for _, b := range ip {
         if b != 0 {
             return false
         }
     }
     return true
}

Instead it would be very very useful to have a Family(), IsIPv4 or IsIPv6
function on net.IP.
What is your opinion on that?


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 16, '16 at 3:02p
activeJun 17, '16 at 2:27p
posts4
users2
websitegolang.org

2 users in discussion

Paul Borman: 2 posts Google: 2 posts

People

Translate

site design / logo © 2021 Grokbase