Golang net.IP.IsLoopback(), IsMulticast() and IsUnspecified() functions example
package net
Golang net.IP.IsLoopback(), IsMulticast() and IsUnspecified() functions usage example
package main
import (
"fmt"
"net"
)
func main() {
ip4 := "127.0.0.1"
// convert to IP type
ipAdd4 := net.ParseIP(ip4)
fmt.Println("127.0.0.1 is a loopback address: ", ipAdd4.IsLoopback())
fmt.Println("127.0.0.1 is a multicast address : ", ipAdd4.IsMulticast())
fmt.Println("127.0.0.1 is an unspecfied address : ", ipAdd4.IsUnspecified())
}
Output :
127.0.0.1 is a loopback address: true
127.0.0.1 is a multicast address : false
127.0.0.1 is an unspecfied address : false
References :
http://golang.org/pkg/net/#IP.IsLoopback
Advertisement
Something interesting
Tutorials
+5.5k Golang : PGX CopyFrom to insert rows into Postgres database
+14.1k Golang : How to determine if a year is leap year?
+31.7k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+17.2k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+8.4k Golang : Find relative luminance or color brightness
+41.4k Golang : How to count duplicate items in slice/array?
+19k Golang : How to make function callback or pass value from function as parameter?
+11.3k Golang : Fix go.exe is not compatible with the version of Windows you're running
+8.4k Golang : Number guessing game with user input verification example
+11.6k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+33.8k Golang : All update packages with go get command