Here, We will learn about type IP in net package in go. type IP provides multiple interfaces to play around IPv4 or IPv6 address.
An IP is a single IP address, a slice of bytes. Functions in type IP in net package in go accept either 4-byte (IPv4) or 16-byte (IPv6) slices as input .
Function prototype:
type IP []byte
Example with code:
package main import ( "fmt" "net" ) func main() { ipv6 := net.IP{0xfd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ipv4 := net.IPv4(10, 10, 10, 0) fmt.Println(ipv6.To4()) fmt.Println(ipv4.To4()) }
Output:
<nil> 10.10.10.0
Functions of type IP
- func IPv4
- func (IP) DefaultMask
- func (IP) IsInterfaceLocalMulticast
- func (IP) IsLoopback
- func (IP) IsUnspecified
- func (IP) To4
- func LookupIP
- func (IP) Equal
- func (IP) IsLinkLocalMulticast
- func (IP) IsMulticast
- func (IP) MarshalText
- func (IP) String
- func (*IP) UnmarshalText
- func ParseIP
- func (IP) IsGlobalUnicast
- func (IP) IsLinkLocalUnicast
- func (IP) IsPrivate
- func (IP) Mask
- func (IP) To16
To learn more about golang, Please refer given below link:
https://techieindoor.com/go-lang-tutorial/
References: https://golang.org/pkg/