Standard library / net
net.IP.To4()
Return four bytes for IPv4 or mapped IPv4; otherwise nil. Expected stdout: '4\n'.
Formal Syntax & Structure
go syntaxgo
func (ip IP) To4() IPReturn Value
IP
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net")
func main() { fmt.Println(len(net.ParseIP("192.0.2.7").To4())) }
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}