Standard library / net/netip
netip.Addr.As4()
Return four bytes for IPv4 or mapped IPv4; panics for invalid or native IPv6. Expected stdout: '[192 0 2 7]\n'.
Formal Syntax & Structure
go syntaxgo
func (ip Addr) As4() (a4 [4]byte)Return Value
(a4 [4]byte)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(netip.MustParseAddr("192.0.2.7").As4()) }
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) }}